From: tsteven4 Date: Sat, 16 Mar 2019 14:40:10 +0000 (-0600) Subject: Introduce a WaypointList class to define the interface to our lists of waypoints... X-Git-Tag: archive/raspbian/1.10.0+ds-2+rpi1~1^2~12^2~8^2~17 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22Program/%22http:/www.example.com/cgi/%22https:/%22Program?a=commitdiff_plain;h=afd089d3187b1ac40422be9aeb5234c156c6b784;p=gpsbabel.git Introduce a WaypointList class to define the interface to our lists of waypoints. (#326) * Introduce a WaypointList class to define the interface to our lists of waypoints. WaypointList is backed QList, eliminating the use of legacy queues for waypoint lists. * try to appease xcode wrt std::abs. * clean up inheritence in WaypointList, RouteList. also quiet clazy with igc and gpsbabel_optional::optional. also improve includes in defs.h. * get rid of unnecessary reinterpret_cast. and correct pointer constness lost by auto. --- diff --git a/arcdist.cc b/arcdist.cc index e929b10ec..ee9dc06df 100644 --- a/arcdist.cc +++ b/arcdist.cc @@ -42,13 +42,7 @@ void ArcDistanceFilter::arcdist_arc_disp_wpt_cb(const Waypoint* arcpt2) if (arcpt2 && arcpt2->latitude != BADVAL && arcpt2->longitude != BADVAL && (ptsopt || (arcpt1 && (arcpt1->latitude != BADVAL && arcpt1->longitude != BADVAL)))) { -#if NEWQ - foreach (Waypoint* waypointp, waypt_list) { -#else - queue* elem, *tmp; - QUEUE_FOR_EACH(&waypt_head, elem, tmp) { - Waypoint* waypointp = reinterpret_cast(elem); -#endif + foreach (Waypoint* waypointp, *global_waypoint_list) { double dist; extra_data* ed; if (waypointp->extra_data) { @@ -107,8 +101,6 @@ void ArcDistanceFilter::process() WayptFunctor arcdist_arc_disp_wpt_cb_f(this, &ArcDistanceFilter::arcdist_arc_disp_wpt_cb); RteHdFunctor arcdist_arc_disp_hdr_cb_f(this, &ArcDistanceFilter::arcdist_arc_disp_hdr_cb); - queue* elem, * tmp; - if (arcfileopt) { int fileline = 0; char* line; @@ -154,12 +146,7 @@ void ArcDistanceFilter::process() } unsigned removed = 0; -#if NEWQ - foreach (Waypoint* wp, waypt_list) { -#else - QUEUE_FOR_EACH(&waypt_head, elem, tmp) { - Waypoint* wp = reinterpret_cast(elem); -#endif + foreach (Waypoint* wp, *global_waypoint_list) { extra_data* ed = (extra_data*) wp->extra_data; wp->extra_data = nullptr; if (ed) { diff --git a/bcr.cc b/bcr.cc index d0814f468..f17232871 100644 --- a/bcr.cc +++ b/bcr.cc @@ -26,14 +26,20 @@ 2007/04&14: new handling of DESCRIPTION lines */ +#include // for M_PI, atan, exp, log, tan +#include // for printf, snprintf, sscanf +#include // for atof, atoi + +#include // for QString, operator+ +#include // for CaseInsensitive +#include // for foreach + #include "defs.h" -#include "csv_util.h" -#include "garmin_tables.h" -#include "inifile.h" -#include -#include -#include -#include +#include "csv_util.h" // for csv_stringclean +#include "garmin_tables.h" // for gt_find_desc_from_icon_number, gt_find_icon_number_from_desc, MAPSOURCE +#include "gbfile.h" // for gbfprintf, gbfclose, gbfopen, gbfile +#include "inifile.h" // for inifile_readstr, inifile_done, inifile_init, inifile_t + #define MYNAME "bcr" @@ -201,11 +207,8 @@ bcr_rd_deinit() static void bcr_create_waypts_from_route(route_head* route) { - queue* elem, *tmp; - - QUEUE_FOR_EACH(&route->waypoint_list, elem, tmp) { - Waypoint* wpt = new Waypoint(*reinterpret_cast(elem)); - waypt_add(wpt); + foreach (const Waypoint* wpt, route->waypoint_list) { + waypt_add(new Waypoint(*wpt)); } } @@ -350,8 +353,6 @@ static void bcr_write_line(gbfile* fout, const QString& key, const int* index, c static void bcr_route_header(const route_head* route) { - queue* elem, *tmp; - Waypoint* wpt; int north, east, nmax, emin; curr_rte_num++; @@ -375,8 +376,7 @@ bcr_route_header(const route_head* route) bcr_write_line(fout, "DESCRIPTIONLINES", nullptr, "0"); int i = 0; - QUEUE_FOR_EACH(&route->waypoint_list, elem, tmp) { - Waypoint* wpt = reinterpret_cast(elem); + foreach (const Waypoint* wpt, route->waypoint_list) { i++; @@ -392,9 +392,8 @@ bcr_route_header(const route_head* route) int emax = nmax = -nmin; i = 0; - QUEUE_FOR_EACH(&route->waypoint_list, elem, tmp) { + foreach (const Waypoint* wpt, route->waypoint_list) { i++; - wpt = reinterpret_cast(elem); bcr_wgs84_to_mercator(wpt->latitude, wpt->longitude, &north, &east); @@ -418,11 +417,10 @@ bcr_route_header(const route_head* route) bcr_write_line(fout, "[DESCRIPTION]", nullptr, nullptr); /* descr. section */ i = 0; - QUEUE_FOR_EACH(&route->waypoint_list, elem, tmp) { + foreach (const Waypoint* wpt, route->waypoint_list) { QString s2; i++; - wpt = reinterpret_cast(elem); QString s1 = wpt->notes; if (s1.isEmpty()) { s1 = wpt->description; diff --git a/bend.cc b/bend.cc index d794ee1d6..92f4b3402 100644 --- a/bend.cc +++ b/bend.cc @@ -20,13 +20,17 @@ */ +#include // macos wants abs from here! +#include // for strtod, abs + +#include // for QString +#include // for qAsConst, QAddConst<>::Type, foreach + #include "defs.h" -#include "bend.h" #include "filterdefs.h" -#include "grtcirc.h" +#include "bend.h" +#include "grtcirc.h" // for RAD, heading_true_degrees, gcdist, linepart, radtometers, DEG -#include -#include #define MYNAME "bend" @@ -90,12 +94,10 @@ int BendFilter::is_small_angle(double lat_orig, double long_orig, double lat_ori void BendFilter::process_route(const route_head* route_orig, route_head* route_dest) { - Waypoint* wpt_orig_prev = nullptr; - Waypoint* wpt_orig = nullptr; + const Waypoint* wpt_orig_prev = nullptr; + const Waypoint* wpt_orig = nullptr; - queue* elem, *tmp; - QUEUE_FOR_EACH(&route_orig->waypoint_list, elem, tmp) { - Waypoint* wpt_orig_next = reinterpret_cast(elem); + foreach (const Waypoint* wpt_orig_next, route_orig->waypoint_list) { if (wpt_orig_prev == nullptr) { if (wpt_orig != nullptr) { @@ -158,8 +160,7 @@ void BendFilter::process_route_orig(const route_head* route_orig) void BendFilter::process() { - for (auto it = routes_orig->cbegin(); it != routes_orig->cend(); ++it) { - auto route_orig = reinterpret_cast(*it); + for (const auto* route_orig : qAsConst(*routes_orig)) { process_route_orig(route_orig); } } diff --git a/bend.h b/bend.h index 904c02999..a9048b99f 100644 --- a/bend.h +++ b/bend.h @@ -25,7 +25,6 @@ #include "defs.h" // for route_head (ptr only), ARGTYPE_FLOAT, ARG_NOMINMAX #include "filter.h" // for Filter -#include "queue.h" // for queue #if FILTERS_ENABLED diff --git a/defs.h b/defs.h index 3e8777179..c51baeeb4 100644 --- a/defs.h +++ b/defs.h @@ -19,26 +19,40 @@ #ifndef DEFS_H_INCLUDED_ #define DEFS_H_INCLUDED_ -#include +#include // for M_PI +#include // for va_list +#include // for NULL, nullptr_t, size_t +#include // for int32_t, uint32_t +#include // for NULL, fprintf, FILE, stdout +#include // for time_t +#include // for move #if HAVE_CONFIG_H #include "config.h" #endif -#include "queue.h" #if HAVE_LIBZ -#include +#include // doesn't really belong here, but is missing elsewhere. #elif !ZLIB_INHIBITED -#include "zlib.h" +#include "zlib.h" // doesn't really belong here, but is missing elsewhere. #endif -#include "gbfile.h" -#include "inifile.h" -#include "session.h" -#include -#include -#include -#include "src/core/datetime.h" -#include "src/core/optional.h" +#include // for QByteArray +#include // for QChar +#include // for QList, QList<>::const_reverse_iterator, QList<>::reverse_iterator +#include // for QString +#include // for QStringRef +#include // for QTextCodec +#include // for CaseInsensitive +#include // for foreach + +#include "cet.h" // for cet_cs_vec_t +#include "inifile.h" // for inifile_t +#include "gbfile.h" // doesn't really belong here, but is missing elsewhere. +#include "queue.h" // for queue +#include "session.h" // for session_t +#include "src/core/datetime.h" // for DateTime +#include "src/core/optional.h" // for optional + #define CSTR(qstr) ((qstr).toUtf8().constData()) #define CSTRc(qstr) ((qstr).toLatin1().constData()) @@ -457,8 +471,6 @@ private: static geocache_data empty_gc_data; public: - queue Q; /* Master waypoint q. Not for use - by modules. */ double latitude; /* Degrees */ double longitude; /* Degrees */ @@ -561,13 +573,57 @@ public: typedef void (*waypt_cb)(const Waypoint*); +// TODO: Consider using composition instead of private inheritance. +class WaypointList : private QList +{ +public: + typedef bool (*Compare)(const Waypoint* a, const Waypoint* b); + + void waypt_add(Waypoint* wpt); // a.k.a. append(), push_back() + void add_rte_waypt(int waypt_ct, Waypoint* wpt, bool synth, const QString& namepart, int number_digits); + // FIXME: Generally it is inefficient to use an element pointer or reference to define the element to be deleted, use iterator instead, + // and/or implement pop_back() a.k.a. removeLast(), and/or pop_front() a.k.a. removeFirst(). + void waypt_del(Waypoint* wpt); // a.k.a. erase() + // FIXME: Generally it is inefficient to use an element pointer or reference to define the element to be deleted, use iterator instead, + // and/or implement pop_back() a.k.a. removeLast(), and/or pop_front() a.k.a. removeFirst(). + void del_rte_waypt(Waypoint* wpt); + void waypt_compute_bounds(bounds* bounds) const; + Waypoint* find_waypt_by_name(const QString& name) const; + void flush(); // a.k.a. clear() + void copy(WaypointList** dst) const; + void restore(WaypointList* src); + void swap(WaypointList& other); + void sort(Compare cmp); + template + void waypt_disp_session(const session_t* se, T cb); + + // Expose limited methods for portability. + // public types + using QList::const_iterator; + using QList::const_reverse_iterator; + using QList::iterator; + using QList::reverse_iterator; + // public functions + using QList::back; // a.k.a. last() + using QList::begin; + using QList::cbegin; + using QList::cend; + using QList::count; // a.k.a. size() + using QList::crbegin; + using QList::crend; + using QList::empty; // a.k.a. isEmpty() + using QList::end; + using QList::front; // a.k.a. first() + using QList::rbegin; + using QList::rend; +}; + const global_trait* get_traits(); void waypt_init(); //void update_common_traits(const Waypoint* wpt); void waypt_add(Waypoint* wpt); void waypt_del(Waypoint* wpt); unsigned int waypt_count(); -void set_waypt_count(unsigned int nc); void waypt_disp(const Waypoint* wpt); void waypt_status_disp(int total_ct, int myct); //void waypt_disp_all(waypt_cb); /* template */ @@ -577,10 +633,12 @@ int waypt_bounds_valid(bounds* bounds); void waypt_add_to_bounds(bounds* bounds, const Waypoint* waypointp); void waypt_compute_bounds(bounds* bounds); Waypoint* find_waypt_by_name(const QString& name); -void waypt_flush(queue* head); void waypt_flush_all(); -void waypt_backup(signed int* count, queue** head_bak); -void waypt_restore(signed int count, queue* head_bak); +void waypt_append(WaypointList* src); +void waypt_backup(WaypointList** head_bak); +void waypt_restore(WaypointList* head_bak); +void waypt_swap(WaypointList& other); +void waypt_sort(WaypointList::Compare cmp); void waypt_add_url(Waypoint* wpt, const QString& link, const QString& url_link_text); void waypt_add_url(Waypoint* wpt, const QString& link, @@ -598,17 +656,10 @@ double waypt_course(const Waypoint* A, const Waypoint* B); template void -waypt_disp_session(const session_t* se, T cb) +WaypointList::waypt_disp_session(const session_t* se, T cb) { - extern queue waypt_head; int i = 0; -#if NEWQ - foreach (Waypoint* waypointp, waypt_list) { -#else - queue* elem, *tmp; - QUEUE_FOR_EACH(&waypt_head, elem, tmp) { - Waypoint* waypointp = reinterpret_cast(elem); -#endif + foreach (Waypoint* waypointp, *this) { if ((se == nullptr) || (waypointp->session == se)) { if (global_opts.verbose_status) { i++; @@ -622,11 +673,22 @@ waypt_disp_session(const session_t* se, T cb) } } +template +void +waypt_disp_session(const session_t* se, T cb) +{ + extern WaypointList* global_waypoint_list; + + global_waypoint_list->waypt_disp_session(se, cb); +} + template void waypt_disp_all(T cb) { - waypt_disp_session(nullptr, cb); + extern WaypointList* global_waypoint_list; + + global_waypoint_list->waypt_disp_session(nullptr, cb); } /* @@ -650,7 +712,7 @@ struct computed_trkdata { class route_head { public: - queue waypoint_list; /* List of child waypoints */ + WaypointList waypoint_list; /* List of child waypoints */ QString rte_name; QString rte_desc; UrlList rte_urls; @@ -710,18 +772,24 @@ public: // Our contained element (route_head) also contains a container (waypoint_list), // and we maintain a total count the elements in these contained containers, i.e. // the total number of waypoints in all the routes in the RouteList. + // public types + using QList::const_iterator; + using QList::const_reverse_iterator; + using QList::iterator; + using QList::reverse_iterator; + // public functions + using QList::back; // a.k.a. last() using QList::begin; - using QList::end; using QList::cbegin; using QList::cend; + using QList::count; // a.k.a. size() + using QList::crbegin; + using QList::crend; using QList::empty; // a.k.a. isEmpty() + using QList::end; using QList::front; // a.k.a. first() - using QList::back; // a.k.a. last() - using QList::count; // a.k.a. size() - using QList::iterator; - using QList::const_iterator; - typedef iterator Iterator; - typedef const_iterator ConstIterator; + using QList::rbegin; + using QList::rend; private: int waypt_ct{0}; @@ -767,11 +835,8 @@ template void route_disp(const route_head* rh, T cb) { - queue* elem, *tmp; // cb != nullptr, caught with an overload of route_disp - QUEUE_FOR_EACH(&rh->waypoint_list, elem, tmp) { - Waypoint* waypointp; - waypointp = reinterpret_cast(elem); + foreach (const Waypoint* waypointp, rh->waypoint_list) { cb(waypointp); } } diff --git a/dmtlog.cc b/dmtlog.cc index a606055b9..9dfc30f70 100644 --- a/dmtlog.cc +++ b/dmtlog.cc @@ -20,11 +20,21 @@ */ -#include +#include // for SEEK_CUR, size_t +#include // int32_t, int16_t, uint32_t +#include // for atoi +#include // for strncmp, memcpy, strcmp, strlen + +#include // for QByteArray +#include // for QString, operator+ +#include // for QXmlStreamAttributes +#include // for qPrintable #include "defs.h" -#include "jeeps/gpsmath.h" -#include "xmlgeneric.h" +#include "gbfile.h" // for gbfgetdbl, gbfgetint32, gbfputint32, gbfgetint16, gbfputdbl, gbfputc, gbfread, gbfseek, gbfgetc, gbfile, gbfclose, gbfungetc, gbfeof, gbfputs, gbfwrite, gbfopen_le, gbfgetuint32, gbfputuint16, gbfputuint32 +#include "jeeps/gpsmath.h" // for GPS_Lookup_Datum_Index, GPS_Math_Known_Datum_To_WGS84_C, GPS_Math_NGENToAiry1830LatLon +#include "xmlgeneric.h" // for cb_cdata, xg_callback, xg_string, xml_deinit, xml_init, cb_end, cb_start, xg_cb_type, xml_read, xml_readstring, xg_tag_mapping + #define MYNAME "dmtlog" @@ -711,8 +721,7 @@ write_header(const route_head* trk) int count = 0; if (trk != nullptr) { - queue* curr, *prev; - QUEUE_FOR_EACH(&trk->waypoint_list, curr, prev) count++; + count = trk->waypoint_list.count(); } if (!trk || trk->rte_name.isEmpty()) { write_str("Name", fout); diff --git a/duplicate.cc b/duplicate.cc index 6d62688c8..e5b5dee55 100644 --- a/duplicate.cc +++ b/duplicate.cc @@ -18,11 +18,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */ + +#include // for sprintf +#include // for qsort +#include // for memset, strncpy + +#include // for QDateTime +#include // for foreach + #include "defs.h" -#include "duplicate.h" #include "filterdefs.h" -#include -#include // qsort +#include "duplicate.h" +#include "src/core/datetime.h" // for DateTime + #if FILTERS_ENABLED @@ -145,19 +153,13 @@ void DuplicateFilter::process() Waypoint* delwpt = nullptr; int ct = waypt_count(); - queue* elem, *tmp; wpt_ptr* htable = (wpt_ptr*) xmalloc(ct * sizeof(*htable)); wpt_ptr* bh = htable; int i = 0; -#if NEWQ - foreach (Waypoint* waypointp, waypt_list) { + foreach (Waypoint* waypointp, *global_waypoint_list) { bh->wpt = waypointp; -#else - QUEUE_FOR_EACH(&waypt_head, elem, tmp) { - bh->wpt = reinterpret_cast(elem); -#endif bh->index = i; i ++; bh ++; diff --git a/filterdefs.h b/filterdefs.h index 389b1fccd..fae64507c 100644 --- a/filterdefs.h +++ b/filterdefs.h @@ -29,15 +29,11 @@ #ifndef FILTERDEFS_H_INCLUDED_ #define FILTERDEFS_H_INCLUDED_ -#if NEWQ -#include -extern QList waypt_list; -#else -#include "queue.h" -extern queue waypt_head; -#endif +#include "defs.h" #include "filter.h" +extern WaypointList* global_waypoint_list; + typedef void (*filter_init)(); typedef void (*filter_process)(); typedef void (*filter_deinit)(); diff --git a/garmin.cc b/garmin.cc index b393706cf..e37c94888 100644 --- a/garmin.cc +++ b/garmin.cc @@ -19,19 +19,30 @@ */ -#include -#include -#include -#include +#include // for isalpha, toupper +#include // for INT_MAX +#include // for atan2, floor, sqrt +#include // for setjmp +#include // for fprintf, fflush, snprintf, sprintf +#include // for atoi, strtol +#include // for memcpy, strlen, strncpy, strchr +#include // for time_t + +#include // for QByteArray +#include // for QChar +#include // for QString +#include // for CaseInsensitive +#include // for qPrintable, foreach -#include "cet_util.h" #include "defs.h" -#include "garmin_device_xml.h" -#include "garmin_fs.h" -#include "garmin_tables.h" -#include "grtcirc.h" +#include "cet_util.h" // for cet_convert_init, cet_cs_vec_utf8 +#include "garmin_device_xml.h" // for gdx_get_info, gdx_info, gdx_file, gdx_jmp_buf +#include "garmin_fs.h" // for garmin_fs_garmin_after_read, garmin_fs_garmin_before_write +#include "garmin_tables.h" // for gt_find_icon_number_from_desc, PCX, gt_find_desc_from_icon_number +#include "grtcirc.h" // for DEG #include "jeeps/gps.h" #include "jeeps/gpsserial.h" +#include "src/core/datetime.h" // for DateTime #define MYNAME "GARMIN" static const char* portname; @@ -910,12 +921,7 @@ waypoint_prepare() { int i; int n = waypt_count(); -#if NEWQ - extern QList waypt_list; -#else - queue* elem, *tmp; - extern queue waypt_head; -#endif + extern WaypointList* global_waypoint_list; int icon; tx_waylist = (struct GPS_SWay**) xcalloc(n,sizeof(*tx_waylist)); @@ -926,13 +932,8 @@ waypoint_prepare() i = 0; -#if NEWQ // Iterate with waypt_disp_all? - foreach(Waypoint* wpt, waypt_list) { -#else - QUEUE_FOR_EACH(&waypt_head, elem, tmp) { - Waypoint* wpt = reinterpret_cast(elem); -#endif + foreach(Waypoint* wpt, *global_waypoint_list) { char obuf[256]; QString src; diff --git a/gdb.cc b/gdb.cc index 6b9bc0090..795b39819 100644 --- a/gdb.cc +++ b/gdb.cc @@ -26,6 +26,7 @@ #include // for atoi, strtol, NULL #include // for memset, strcmp, strstr, strchr, strlen, strncpy #include // for strftime +#include // for next #include // for QByteArray #include // for QList @@ -41,7 +42,6 @@ #include "gbfile.h" // for gbfputint32, gbfgetint32, gbfread, gbfwrite, gbfgetc, gbfputc, gbfgetdbl, gbfgetcstr, gbfile, gbfclose, gbfputcstr, gbfcopyfrom, gbfrewind, gbfseek, gbftell, gbfopen_le, gbfgetcstr_old, gbfgetint16, gbfputdbl, gbfputint16 #include "grtcirc.h" // for RAD, gcdist, radtometers #include "jeeps/gpsmath.h" // for GPS_Math_Deg_To_Semi, GPS_Math_Semi_To_Deg -#include "queue.h" // for queue, QUEUE_FOR_EACH #include "src/core/datetime.h" // for DateTime @@ -1396,10 +1396,8 @@ write_waypoint( static void route_compute_bounds(const route_head* rte, bounds* bounds) { - queue* elem, *tmp; waypt_init_bounds(bounds); - QUEUE_FOR_EACH((queue*)&rte->waypoint_list, elem, tmp) { - Waypoint* wpt = reinterpret_cast(elem); + foreach (Waypoint* wpt, rte->waypoint_list) { gdb_check_waypt(wpt); waypt_add_to_bounds(bounds, wpt); } @@ -1425,7 +1423,6 @@ static void write_route(const route_head* rte, const QString& rte_name) { bounds bounds; - queue* elem, *tmp; char zbuf[32], ffbuf[32]; memset(zbuf, 0, sizeof(zbuf)); @@ -1442,10 +1439,13 @@ write_route(const route_head* rte, const QString& rte_name) int index = 0; - QUEUE_FOR_EACH((queue*)&rte->waypoint_list, elem, tmp) { + for (auto it =rte->waypoint_list.cbegin(); it != rte->waypoint_list.cend(); ++it) { - Waypoint* wpt = reinterpret_cast(elem); - Waypoint* next = reinterpret_cast(tmp); + Waypoint* wpt = *it; + Waypoint* next = nullptr; + if (index < points) { + next = *std::next(it); + } index++; rtept_ct++; /* increase informational number of written route points */ @@ -1543,7 +1543,6 @@ write_route(const route_head* rte, const QString& rte_name) static void write_track(const route_head* trk, const QString& trk_name) { - queue* elem, *tmp; int points = ELEMENTS(trk); FWRITE_CSTR(trk_name); @@ -1553,8 +1552,7 @@ write_track(const route_head* trk, const QString& trk_name) FWRITE_i32(points); /* total number of waypoints in waypoint list */ - QUEUE_FOR_EACH((queue*)&trk->waypoint_list, elem, tmp) { - Waypoint* wpt = reinterpret_cast(elem); + foreach (const Waypoint* wpt, trk->waypoint_list) { trkpt_ct++; /* increase informational number of written route points */ diff --git a/ggv_log.cc b/ggv_log.cc index 0806a41b0..ed5f1735c 100644 --- a/ggv_log.cc +++ b/ggv_log.cc @@ -20,14 +20,22 @@ */ -#include -#include -#include -#include +#include // for fabs, floor, lround +#include // for sscanf +#include // for memset, strncmp +#include // for int16_t +#include // for gmtime + +#include // for QString +#include // for QTime +#include // for foreach #include "defs.h" -#include "grtcirc.h" -#include "jeeps/gpsmath.h" +#include "gbfile.h" // for gbfputint16, gbfclose, gbfopen, gbfputflt, gbfgetc, gbfputcstr, gbfputdbl, gbfread, gbfile +#include "grtcirc.h" // for heading_true_degrees +#include "src/core/datetime.h" // for DateTime + + #define MYNAME "ggv_log" @@ -196,13 +204,11 @@ ggv_log_wr_deinit() static void ggv_log_track_head_cb(const route_head* trk) { - queue* elem, *tmp; - Waypoint* prev = nullptr; + const Waypoint* prev = nullptr; - QUEUE_FOR_EACH((queue*)&trk->waypoint_list, elem, tmp) { + foreach (const Waypoint* wpt, trk->waypoint_list) { double course = 0, speed = 0; struct tm tm; - Waypoint* wpt = reinterpret_cast(elem); double secs = 0; int latint = wpt->latitude; diff --git a/ggv_ovl.cc b/ggv_ovl.cc index 9fbcd8b0f..aa2aa11e0 100644 --- a/ggv_ovl.cc +++ b/ggv_ovl.cc @@ -20,14 +20,17 @@ */ +#include // for sin, cos, acos +#include // for snprintf + +#include // for QString +#include // for foreach + #include "defs.h" -#include "grtcirc.h" -#include "inifile.h" +#include "gbfile.h" // for gbfprintf, gbfclose, gbfopen, gbfile +#include "grtcirc.h" // for RAD, gcdist, DEG +#include "inifile.h" // for inifile_readstr, inifile_readint_def, inifile_done, inifile_init, inifile_readint, inifile_t -#include -#include -#include -#include #define MYNAME "ggv_ovl" @@ -268,7 +271,6 @@ waypt_disp_cb(const Waypoint* wpt) static void track_disp_cb(const route_head* trk) { - queue* elem, *tmp; int waypt_ct = trk->rte_waypt_ct; if (waypt_ct <= 0) { @@ -283,9 +285,7 @@ track_disp_cb(const route_head* trk) int i = 0; - QUEUE_FOR_EACH(&(trk->waypoint_list), elem, tmp) { - - Waypoint* wpt = reinterpret_cast(elem); + foreach (const Waypoint* wpt, trk->waypoint_list) { gbfprintf(fout, "XKoord%d=%0.8f\n", i, wpt->longitude); gbfprintf(fout, "YKoord%d=%0.8f\n", i, wpt->latitude); @@ -299,7 +299,6 @@ track_disp_cb(const route_head* trk) static void route_disp_cb(const route_head* rte) { - queue* elem, *tmp; int waypt_ct = rte->rte_waypt_ct; if (waypt_ct <= 0) { @@ -311,11 +310,9 @@ route_disp_cb(const route_head* rte) color = OVL_COLOR_RED; int i = 0; - Waypoint* prev = nullptr; - - QUEUE_FOR_EACH(&(rte->waypoint_list), elem, tmp) { + const Waypoint* prev = nullptr; - Waypoint* wpt = reinterpret_cast(elem); + foreach (const Waypoint* wpt, rte->waypoint_list) { if (prev != nullptr) { draw_symbol_basics(OVL_SYMBOL_TRIANGLE, 1, (OVL_COLOR_TYP)9 /* color */, prev); diff --git a/gpx.cc b/gpx.cc index 41d1d3e4c..52d09d0f2 100644 --- a/gpx.cc +++ b/gpx.cc @@ -19,6 +19,30 @@ */ +#include // for lround +#include // for sscanf +#include // for atoi, strtod +#include // for strchr, strncpy + +#include // for QDate +#include // for QDateTime +#include // for QHash +#include // for QIODevice, operator|, QIODevice::ReadOnly, QIODevice::Text, QIODevice::WriteOnly +#include // for QLatin1String +#include // for QStaticStringData +#include // for QString, QStringLiteral, operator+, operator== +#include // for QStringList +#include // for QStringRef +#include // for QTime +#include // for QVector +#include // for QXmlStreamAttribute +#include // for QXmlStreamAttributes +#include // for QXmlStreamNamespaceDeclaration +#include // for QXmlStreamNamespaceDeclarations +#include // for QXmlStreamReader, QXmlStreamReader::Characters, QXmlStreamReader::EndDocument, QXmlStreamReader::EndElement, QXmlStreamReader::Invalid, QXmlStreamReader::StartElement +#include // for CaseInsensitive, UTC +#include // for qAsConst, QAddConst<>::Type + #include "defs.h" #include "garmin_fs.h" #include "garmin_tables.h" @@ -28,21 +52,6 @@ #include "src/core/xmlstreamwriter.h" #include "src/core/xmltag.h" -#include // for QDateTime, QDate, QTime -#include // for QHash -#include // for QList -#include // for QString, QStringLiteral, QStringRef, QStaticStringData, QLatin1String, operator+ -#include // for QStringList -#include // for QXmlStreamAttributes -#include // for QXmlStreamNamespaceDeclarations -#include // for QXmlStreamReader, QXmlStreamReader::TokenType::Characters, QXmlStreamReader::TokenType::EndDocument, QXmlStreamReader::TokenType::EndElement, QXmlStreamReader::TokenType::Invalid, QXmlStreamReader::TokenType::StartElement -#include // for qAsConst - -#include // for lround -#include // for sscanf -#include // for atoi, strtod -#include // for strchr - static QXmlStreamReader* reader; static xml_tag* cur_tag; @@ -1827,7 +1836,7 @@ gpx_track_hdr(const route_head* rte) static void gpx_track_disp(const Waypoint* waypointp) { - bool first_in_trk = waypointp->Q.prev == ¤t_trk_head->waypoint_list; + bool first_in_trk = waypointp == current_trk_head->waypoint_list.front(); if (waypointp->wpt_flags.new_trkseg) { if (!first_in_trk) { @@ -1864,7 +1873,7 @@ gpx_track_disp(const Waypoint* waypointp) static void gpx_track_tlr(const route_head*) { - if (!QUEUE_EMPTY(¤t_trk_head->waypoint_list)) { + if (!current_trk_head->waypoint_list.empty()) { writer->writeEndElement(); } diff --git a/igc.cc b/igc.cc index 2bccfaf51..eefed682a 100644 --- a/igc.cc +++ b/igc.cc @@ -23,12 +23,25 @@ * 59 Temple Place - Suite 330, Boston, MA 02111 USA */ +#include // for fabs, lround +#include // for sscanf, snprintf, fputs, printf, stdout, putchar, size_t +#include // for labs, ldiv, ldiv_t, abs +#include // for strcmp, strlen, strtok, strcat, strchr, strcpy, strncat +#include // for gmtime, ctime +#include // for reverse_iterator, operator==, prev, next + +#include // for QByteArray +#include // for QList<>::const_iterator +#include // for QStaticStringData +#include // for QString, operator+, QStringLiteral +#include // for foreach, qPrintable + #include "defs.h" -#include "cet_util.h" -#include -#include -#include -#include +#include "cet_util.h" // for cet_convert_init +#include "gbfile.h" // for gbfprintf, gbfclose, gbfopen, gbfputs, gbfgetstr, gbfile +#include "src/core/datetime.h" // for DateTime +#include "src/core/optional.h" // for optional + static gbfile* file_in, *file_out; static char manufacturer[4]; @@ -590,7 +603,7 @@ static void wr_header() } // Date in header record is that of the first fix record date = !track ? current_time().toTime_t() : - (reinterpret_castQUEUE_FIRST(&track->waypoint_list))->GetCreationTime().toTime_t(); + track->waypoint_list.front()->GetCreationTime().toTime_t(); if (nullptr == (tm = gmtime(&date))) { fatal(MYNAME ": Bad track timestamp\n"); @@ -662,11 +675,11 @@ static void wr_task_hdr(const route_head* rte) } // See if the takeoff and landing waypoints are there or if we need to // generate them. - const Waypoint* wpt = reinterpret_castQUEUE_LAST(&rte->waypoint_list); + const Waypoint* wpt = rte->waypoint_list.back(); if (wpt->shortname.startsWith("LANDING")) { num_tps--; } - wpt = reinterpret_castQUEUE_FIRST(&rte->waypoint_list); + wpt = rte->waypoint_list.front(); if (wpt->shortname.startsWith("TAKEOFF")) { have_takeoff = 1; num_tps--; @@ -704,7 +717,7 @@ static void wr_task_wpt(const Waypoint* wpt) static void wr_task_tlr(const route_head* rte) { // If the landing waypoint is not supplied we need to generate it. - const Waypoint* wpt = reinterpret_castQUEUE_LAST(&rte->waypoint_list); + const Waypoint* wpt = rte->waypoint_list.back(); QString sn = wpt->shortname; // if (!wpt->shortname || strncmp(wpt->shortname, "LANDIN", 6) != 0) { if (sn.isEmpty() || !sn.startsWith("LANDIN")) { @@ -757,45 +770,45 @@ static int correlate_tracks(const route_head* pres_track, const route_head* gnss // Deduce the landing time from the pressure altitude track based on // when we last descended to within 10m of the final track altitude. - const queue* elem = QUEUE_LAST(&pres_track->waypoint_list); - double last_alt = (reinterpret_cast(elem))->altitude; + WaypointList::const_reverse_iterator wpt_rit = pres_track->waypoint_list.crbegin(); + double last_alt = (*wpt_rit)->altitude; do { - elem = elem->prev; - if (&pres_track->waypoint_list == elem) { + ++wpt_rit; + if (pres_track->waypoint_list.crend() == wpt_rit) { // No track left return 0; } - alt_diff = last_alt - (reinterpret_cast(elem))->altitude; + alt_diff = last_alt - (*wpt_rit)->altitude; if (alt_diff > 10.0) { // Last part of track was ascending return 0; } } while (alt_diff > -10.0); - pres_time = (reinterpret_cast(elem->next))->GetCreationTime().toTime_t(); + pres_time = (*std::prev(wpt_rit))->GetCreationTime().toTime_t(); if (global_opts.debug_level >= 1) { printf(MYNAME ": pressure landing time %s", ctime(&pres_time)); } + // Deduce the landing time from the GNSS altitude track based on // when the groundspeed last dropped below a certain level. - elem = QUEUE_LAST(&gnss_track->waypoint_list); - last_alt = (reinterpret_cast(elem))->altitude; + wpt_rit = gnss_track->waypoint_list.crbegin(); do { - const Waypoint* wpt = reinterpret_cast(elem); - elem = elem->prev; - if (&gnss_track->waypoint_list == elem) { + const Waypoint* wpt = *wpt_rit; + ++wpt_rit; + if (gnss_track->waypoint_list.crend() == wpt_rit) { // No track left return 0; } // Get a crude indication of groundspeed from the change in lat/lon - time_diff = wpt->GetCreationTime().toTime_t() - (reinterpret_cast(elem))->GetCreationTime().toTime_t(); + time_diff = wpt->GetCreationTime().toTime_t() - (*wpt_rit)->GetCreationTime().toTime_t(); speed = !time_diff ? 0 : - (fabs(wpt->latitude - (reinterpret_cast(elem))->latitude) + - fabs(wpt->longitude - (reinterpret_cast(elem))->longitude)) / time_diff; + (fabs(wpt->latitude - (*wpt_rit)->latitude) + + fabs(wpt->longitude - (*wpt_rit)->longitude)) / time_diff; if (global_opts.debug_level >= 2) { printf(MYNAME ": speed=%f\n", speed); } } while (speed < 0.00003); - gnss_time = (reinterpret_cast(elem->next))->GetCreationTime().toTime_t(); + gnss_time = (*std::prev(wpt_rit))->GetCreationTime().toTime_t(); if (global_opts.debug_level >= 1) { printf(MYNAME ": gnss landing time %s", ctime(&gnss_time)); } @@ -814,43 +827,42 @@ static int correlate_tracks(const route_head* pres_track, const route_head* gnss */ static double interpolate_alt(const route_head* track, time_t time) { - static const queue* prev_elem = nullptr; - static const queue* curr_elem = nullptr; + static gpsbabel_optional::optional prev_wpt; + static gpsbabel_optional::optional curr_wpt; int time_diff; // Start search at the beginning of the track - if (!prev_elem) { - curr_elem = prev_elem = QUEUE_FIRST(&track->waypoint_list); + if (!prev_wpt.has_value()) { + prev_wpt = track->waypoint_list.cbegin(); + curr_wpt = track->waypoint_list.cbegin(); } // Find the track points either side of the requested time - while ((reinterpret_cast(curr_elem))->GetCreationTime().toTime_t() < time) { - if (QUEUE_LAST(&track->waypoint_list) == curr_elem) { - // Requested time later than all track points, we can't interpolate - return unknown_alt; - } - prev_elem = curr_elem; - curr_elem = QUEUE_NEXT(prev_elem); + while ((track->waypoint_list.cend() != curr_wpt.value()) && + ((*curr_wpt.value())->GetCreationTime().toTime_t() < time)) { + prev_wpt = curr_wpt.value(); + curr_wpt = std::next(prev_wpt.value()); + } + if (track->waypoint_list.cend() == curr_wpt.value()) { + // Requested time later than all track points, we can't interpolate + return unknown_alt; } - const Waypoint* prev_wpt = reinterpret_cast(prev_elem); - const Waypoint* curr_wpt = reinterpret_cast(curr_elem); - - if (QUEUE_FIRST(&track->waypoint_list) == curr_elem) { - if (curr_wpt->GetCreationTime().toTime_t() == time) { + if (track->waypoint_list.cbegin() == curr_wpt.value()) { + if ((*curr_wpt.value())->GetCreationTime().toTime_t() == time) { // First point's creation time is an exact match so use it's altitude - return curr_wpt->altitude; + return (*curr_wpt.value())->altitude; } else { // Requested time is prior to any track points, we can't interpolate return unknown_alt; } } // Interpolate - if (0 == (time_diff = curr_wpt->GetCreationTime().toTime_t() - prev_wpt->GetCreationTime().toTime_t())) { + if (0 == (time_diff = (*curr_wpt.value())->GetCreationTime().toTime_t() - (*prev_wpt.value())->GetCreationTime().toTime_t())) { // Avoid divide by zero - return curr_wpt->altitude; + return (*curr_wpt.value())->altitude; } - double alt_diff = curr_wpt->altitude - prev_wpt->altitude; - return prev_wpt->altitude + (alt_diff / time_diff) * (time - prev_wpt->GetCreationTime().toTime_t()); + double alt_diff = (*curr_wpt.value())->altitude - (*prev_wpt.value())->altitude; + return (*prev_wpt.value())->altitude + (alt_diff / time_diff) * (time - (*prev_wpt.value())->GetCreationTime().toTime_t()); } /* @@ -881,11 +893,7 @@ static void wr_track() printf(MYNAME ": adjusting time by %ds\n", time_adj); } // Iterate through waypoints in both tracks simultaneously - const queue* elem; - const queue* tmp; - QUEUE_FOR_EACH(&gnss_track->waypoint_list, elem, tmp) { - // FIXME(NEW_Q): the excessive casting of the iterators is gross. Rethink. - const Waypoint* wpt = reinterpret_cast(elem); + foreach (const Waypoint* wpt, gnss_track->waypoint_list) { double pres_alt = interpolate_alt(pres_track, wpt->GetCreationTime().toTime_t() + time_adj); wr_fix_record(wpt, pres_alt, wpt->altitude); } @@ -893,19 +901,13 @@ static void wr_track() if (pres_track) { // Only the pressure altitude track was found so generate fix // records from it alone. - const queue* elem; - const queue* tmp; - QUEUE_FOR_EACH(&pres_track->waypoint_list, elem, tmp) { - const Waypoint* wpt = reinterpret_cast(elem); + foreach (const Waypoint* wpt, pres_track->waypoint_list) { wr_fix_record(wpt, wpt->altitude, unknown_alt); } } else if (gnss_track) { // Only the GNSS altitude track was found so generate fix // records from it alone. - const queue* elem; - const queue* tmp; - QUEUE_FOR_EACH(&gnss_track->waypoint_list, elem, tmp) { - const Waypoint* wpt = reinterpret_cast(elem); + foreach (const Waypoint* wpt, gnss_track->waypoint_list) { wr_fix_record(wpt, unknown_alt, wpt->altitude); } } else { diff --git a/interpolate.cc b/interpolate.cc index fa8933fc8..a46fdf184 100644 --- a/interpolate.cc +++ b/interpolate.cc @@ -19,11 +19,17 @@ */ +#include // for atoi, strtod + +#include // for QString +#include // for qAsConst, QAddConst<>::Type, foreach + #include "defs.h" #include "filterdefs.h" -#include "grtcirc.h" #include "interpolate.h" -#include +#include "grtcirc.h" // for linepart, RAD, gcdist, radtomiles +#include "src/core/datetime.h" // for DateTime + #if FILTERS_ENABLED #define MYNAME "Interpolate filter" @@ -31,7 +37,6 @@ void InterpolateFilter::process() { RouteList* backuproute = nullptr; - queue* elem2, *tmp2; double lat1 = 0, lon1 = 0; double altitude1 = unknown_alt; unsigned int time1 = 0; @@ -49,8 +54,7 @@ void InterpolateFilter::process() fatal(MYNAME ": Found no routes or tracks to operate on.\n"); } - for (auto it = backuproute->cbegin(); it != backuproute->cend(); ++it) { - auto rte_old = reinterpret_cast(*it); + for (const auto* rte_old : qAsConst(*backuproute)) { route_head* rte_new = route_head_alloc(); rte_new->rte_name = rte_old->rte_name; @@ -63,8 +67,7 @@ void InterpolateFilter::process() track_add_head(rte_new); } bool first = true; - QUEUE_FOR_EACH(&rte_old->waypoint_list, elem2, tmp2) { - Waypoint* wpt = reinterpret_cast(elem2); + foreach (const Waypoint* wpt, rte_old->waypoint_list) { if (first) { first = false; } else { diff --git a/kml.cc b/kml.cc index 11c09db59..45217908d 100644 --- a/kml.cc +++ b/kml.cc @@ -24,26 +24,35 @@ # include #endif -#include "defs.h" -#include "grtcirc.h" -#include "queue.h" -#include "src/core/datetime.h" -#include "src/core/file.h" -#include "src/core/xmlstreamwriter.h" -#include "src/core/xmltag.h" -#include "xmlgeneric.h" -#include // for QXmlStreamAttributes +#include // for tolower, toupper +#include // for fabs +#include // for sscanf, printf +#include // for atoi, atol, atof +#include // for strcmp +#include // for tuple, make_tuple, tie + +#include // for QByteArray +#include // for QChar +#include // for QDate #include // for QDateTime #include // for QFile +#include // for operator|, QIODevice, QIODevice::Text, QIODevice::WriteOnly #include // for QList -#include // for QString, QStringLiteral, QStat... -#include // for qint64, qPrintable -#include -#include -#include -#include -#include -#include +#include // for QStaticStringData +#include // for QString, QStringLiteral, operator+, operator!= +#include // for QXmlStreamAttributes +#include // for ISODate +#include // for foreach, qint64, qPrintable + +#include "defs.h" +#include "grtcirc.h" // for RAD, gcdist, radtometers +#include "src/core/datetime.h" // for DateTime +#include "src/core/file.h" // for File +#include "src/core/optional.h" // for optional +#include "src/core/xmlstreamwriter.h" // for XmlStreamWriter +#include "src/core/xmltag.h" // for xml_findfirst, xml_tag, fs_xml, xml_attribute, xml_findnext +#include "xmlgeneric.h" // for cb_cdata, cb_end, cb_start, xg_callback, xg_string, xg_cb_type, xml_deinit, xml_ignore_tags, xml_init, xml_read, xg_tag_mapping + // options static char* opt_deficon = nullptr; @@ -443,10 +452,7 @@ void trk_coord(xg_string args, const QXmlStreamAttributes*) if (trk_head->rte_waypt_ct > 0) { qint64 timespan_ms = wpt_timespan_begin.msecsTo(wpt_timespan_end); qint64 ms_per_waypoint = timespan_ms / trk_head->rte_waypt_ct; - queue* curr_elem; - queue* tmp_elem; - QUEUE_FOR_EACH(&trk_head->waypoint_list, curr_elem, tmp_elem) { - trkpt = reinterpret_cast(curr_elem); + foreach (Waypoint* trkpt, trk_head->waypoint_list) { trkpt->SetCreationTime(wpt_timespan_begin); wpt_timespan_begin = wpt_timespan_begin.addMSecs(ms_per_waypoint); } @@ -1095,11 +1101,9 @@ static void kml_output_tailer(const route_head* header) // Add a linestring for this track? if (export_lines && header->rte_waypt_ct > 0) { int needs_multigeometry = 0; - queue* elem, *tmp; - QUEUE_FOR_EACH(&header->waypoint_list, elem, tmp) { - Waypoint* tpt = reinterpret_cast(elem); - int first_in_trk = tpt->Q.prev == &header->waypoint_list; + foreach (const Waypoint* tpt, header->waypoint_list) { + int first_in_trk = tpt == header->waypoint_list.front(); if (!first_in_trk && tpt->wpt_flags.new_trkseg) { needs_multigeometry = 1; break; @@ -1134,9 +1138,8 @@ static void kml_output_tailer(const route_head* header) writer->writeStartElement(QStringLiteral("MultiGeometry")); } - QUEUE_FOR_EACH(&header->waypoint_list, elem, tmp) { - Waypoint* tpt = reinterpret_cast(elem); - int first_in_trk = tpt->Q.prev == &header->waypoint_list; + foreach (const Waypoint* tpt, header->waypoint_list) { + int first_in_trk = tpt == header->waypoint_list.front(); if (tpt->wpt_flags.new_trkseg) { if (!first_in_trk) { writer->writeEndElement(); // Close coordinates tag @@ -1717,13 +1720,10 @@ static void kml_mt_simple_array(const route_head* header, const char* name, wp_field member) { - queue* elem, *tmp; writer->writeStartElement(QStringLiteral("gx:SimpleArrayData")); writer->writeAttribute(QStringLiteral("name"), name); - QUEUE_FOR_EACH(&header->waypoint_list, elem, tmp) { - - Waypoint* wpt = reinterpret_cast(elem); + foreach (const Waypoint* wpt, header->waypoint_list) { switch (member) { case fld_power: @@ -1751,11 +1751,8 @@ static void kml_mt_simple_array(const route_head* header, // True if at least two points in the track have timestamps. static int track_has_time(const route_head* header) { - queue* elem, *tmp; int points_with_time = 0; - QUEUE_FOR_EACH(&header->waypoint_list, elem, tmp) { - Waypoint* tpt = reinterpret_cast(elem); - + foreach (const Waypoint* tpt, header->waypoint_list) { if (tpt->GetCreationTime().isValid()) { points_with_time++; if (points_with_time >= 2) { @@ -1769,10 +1766,8 @@ static int track_has_time(const route_head* header) // Simulate a track_disp_all callback sequence for a single track. static void write_as_linestring(const route_head* header) { - queue* elem, *tmp; kml_track_hdr(header); - QUEUE_FOR_EACH(&header->waypoint_list, elem, tmp) { - Waypoint* tpt = reinterpret_cast(elem); + foreach (const Waypoint* tpt, header->waypoint_list) { kml_track_disp(tpt); } kml_track_tlr(header); @@ -1781,7 +1776,6 @@ static void write_as_linestring(const route_head* header) static void kml_mt_hdr(const route_head* header) { - queue* elem, *tmp; int has_cadence = 0; int has_depth = 0; int has_heartrate = 0; @@ -1801,9 +1795,7 @@ static void kml_mt_hdr(const route_head* header) writer->writeStartElement(QStringLiteral("gx:Track")); kml_output_positioning(false); - QUEUE_FOR_EACH(&header->waypoint_list, elem, tmp) { - Waypoint* tpt = reinterpret_cast(elem); - + foreach (const Waypoint* tpt, header->waypoint_list) { if (tpt->GetCreationTime().isValid()) { QString time_string = tpt->CreationTimeXML(); writer->writeOptionalTextElement(QStringLiteral("when"), time_string); @@ -1814,9 +1806,7 @@ static void kml_mt_hdr(const route_head* header) } // TODO: How to handle clamped, floating, extruded, etc.? - QUEUE_FOR_EACH(&header->waypoint_list, elem, tmp) { - Waypoint* tpt = reinterpret_cast(elem); - + foreach (const Waypoint* tpt, header->waypoint_list) { if (kml_altitude_known(tpt)) { writer->writeTextElement(QStringLiteral("gx:coord"), QString::number(tpt->longitude, 'f', precision) + QString(" ") + @@ -2192,7 +2182,7 @@ kml_wr_position(Waypoint* wpt) track points if we've not moved a minimum distance from the beginning of our accumulated track. */ { - Waypoint* newest_posn= reinterpret_castQUEUE_LAST(&posn_trk_head->waypoint_list); + Waypoint* newest_posn= posn_trk_head->waypoint_list.back(); if (radtometers(gcdist(RAD(wpt->latitude), RAD(wpt->longitude), RAD(newest_posn->latitude), RAD(newest_posn->longitude))) > 50) { @@ -2217,7 +2207,7 @@ kml_wr_position(Waypoint* wpt) */ while (max_position_points && (posn_trk_head->rte_waypt_ct >= max_position_points)) { - Waypoint* tonuke = reinterpret_castQUEUE_FIRST(&posn_trk_head->waypoint_list); + Waypoint* tonuke = posn_trk_head->waypoint_list.front(); track_del_wpt(posn_trk_head, tonuke); } diff --git a/lowranceusr.cc b/lowranceusr.cc index 400b64353..e51acca31 100644 --- a/lowranceusr.cc +++ b/lowranceusr.cc @@ -85,18 +85,26 @@ */ +#include // for M_PI, atan, exp, log, tan +#include // for printf, snprintf, sprintf, SEEK_CUR +#include // for atoi, abs +#include // for strlen, strcmp +#include + +#include // for QByteArray +#include // for QDate +#include // for QDateTime +#include // for QLatin1String +#include // for QString, operator+, operator==, operator!= +#include // for QTextCodec +#include // for QTime +#include // for CaseInsensitive, UTC +#include // for qPrintable, uint, foreach #include "defs.h" -#include "src/core/datetime.h" -#include -#include -#include -#include -#include -#include -#include // for lat/lon conversion -#include // for gmtime -#include // atoi +#include "gbfile.h" // for gbfgetint32, gbfputint32, gbfputint16, gbfgetc, gbfgetint16, gbfputc, gbfwrite, gbfeof, gbfgetflt, gbfclose, gbfgetdbl, gbfputdbl, gbfile, gbfputflt, gbfread, gbfseek, gbfopen_le +#include "src/core/datetime.h" // for DateTime + typedef struct lowranceusr_icon_mapping { const int value; @@ -332,11 +340,7 @@ static int waypt_table_sz; static int waypt_table_ct; /* from waypt.c, we need to iterate over waypoints when extracting routes */ -#if NEWQ -extern QList waypt_list; -#else -extern queue waypt_head; -#endif +extern WaypointList* global_waypoint_list; static unsigned short waypt_out_count; static int trail_count, lowrance_route_count; @@ -470,18 +474,10 @@ register_waypt(const Waypoint* ref) static Waypoint* lowranceusr4_find_waypt(uint uid_unit, int uid_seq_low, int uid_seq_high) { -#if !NEWQ - queue* elem, *tmp; -#endif lowranceusr4_fsdata* fs = nullptr; -#if NEWQ // Iterate with waypt_disp_all? - foreach (Waypoint* waypointp, waypt_list) { -#else - QUEUE_FOR_EACH(&waypt_head, elem, tmp) { - Waypoint* waypointp = reinterpret_cast(elem); -#endif + foreach (Waypoint* waypointp, *global_waypoint_list) { fs = (lowranceusr4_fsdata*) fs_chain_find(waypointp->fs, FS_LOWRANCEUSR4); if (fs && fs->uid_unit == uid_unit && @@ -501,18 +497,10 @@ lowranceusr4_find_waypt(uint uid_unit, int uid_seq_low, int uid_seq_high) static Waypoint* lowranceusr4_find_global_waypt(uint id1, uint id2, uint id3, uint id4) { -#if !NEWQ - queue* elem, *tmp; -#endif lowranceusr4_fsdata* fs = nullptr; -#if NEWQ // Iterate with waypt_disp_all? - foreach (Waypoint* waypointp, waypt_list) { -#else - QUEUE_FOR_EACH(&waypt_head, elem, tmp) { - Waypoint* waypointp = reinterpret_cast(elem); -#endif + foreach (Waypoint* waypointp, *global_waypoint_list) { fs = (lowranceusr4_fsdata*) fs_chain_find(waypointp->fs, FS_LOWRANCEUSR4); if (fs && fs->UUID1 == id1 && diff --git a/magproto.cc b/magproto.cc index 58f1045e4..145aec092 100644 --- a/magproto.cc +++ b/magproto.cc @@ -47,7 +47,6 @@ #include "gbfile.h" // for gbfclose, gbfeof, gbfgets, gbfopen, gbfwrite, gbfile #include "gbser.h" // for gbser_deinit, gbser_init, gbser_is_serial, gbser_read_line, gbser_set_port, gbser_write, gbser_OK #include "magellan.h" // for mm_meridian, mm_sportrak, icon_mapping_t, mm_gps315320, mm_unknown, mm_map330, mm_map410, pid_to_model_t, mm_gps310, m330_cleanse, mag_checksum, mag_find_descr_from_token, mag_find_token_from_descr, mag_rteparse, mag_trkparse -#include "queue.h" // for queue, QUEUE_FOR_EACH #include "src/core/datetime.h" // for DateTime @@ -1073,7 +1072,7 @@ mag_rteparse(char* rtemsg) /* * This is the first component of a route. Allocate a new - * queue head. + * head. */ if (frag == 1) { mag_rte_head = new mag_rte_head_t; @@ -1481,7 +1480,6 @@ and to replace the 2nd name with "<<>>", but I haven't seen one of those. static void mag_route_trl(const route_head* rte) { - queue* elem, *tmp; char obuff[256]; char buff1[64], buff2[64]; char* pbuff; @@ -1497,8 +1495,7 @@ mag_route_trl(const route_head* rte) route_out_count++; int thisline = i = 0; - QUEUE_FOR_EACH(&rte->waypoint_list, elem, tmp) { - Waypoint* waypointp = reinterpret_cast(elem); + foreach (const Waypoint* waypointp, rte->waypoint_list) { i++; if (deficon) { @@ -1515,7 +1512,7 @@ mag_route_trl(const route_head* rte) // Write name, icon tuple into alternating buff1/buff2 buffer. sprintf(pbuff, "%s,%s", CSTR(waypointp->shortname), CSTR(icon_token)); - if ((tmp == &rte->waypoint_list) || ((i % 2) == 0)) { + if ((waypointp == rte->waypoint_list.back()) || ((i % 2) == 0)) { char expbuf[1024]; thisline++; expbuf[0] = 0; diff --git a/main.cc b/main.cc index cbf1d3621..159098b29 100644 --- a/main.cc +++ b/main.cc @@ -49,7 +49,6 @@ #include "filter.h" // for Filter #include "filterdefs.h" // for disp_filter_vec, disp_filter_vecs, disp_filters, exit_filter_vecs, find_filter_vec, free_filter_vec, init_filter_vecs #include "inifile.h" // for inifile_done, inifile_init -#include "queue.h" // for queue #include "session.h" // for start_session, session_exit, session_init #include "src/core/datetime.h" // for DateTime #include "src/core/file.h" // for File @@ -228,9 +227,9 @@ run(const char* prog_name) const char* fvec_opts = nullptr; int opt_version = 0; bool did_something = false; - queue* wpt_head_bak; - RouteList* rte_head_bak, *trk_head_bak; - signed int wpt_ct_bak; + WaypointList* wpt_head_bak; + RouteList* rte_head_bak; + RouteList* trk_head_bak; bool lists_backedup; QStack qargs_stack; @@ -350,7 +349,9 @@ run(const char* prog_name) cet_convert_init(ovecs->encode, ovecs->fixed_encode); lists_backedup = false; - rte_head_bak = trk_head_bak = nullptr; + wpt_head_bak = nullptr; + rte_head_bak = nullptr; + trk_head_bak = nullptr; ovecs->wr_init(ofname); @@ -364,7 +365,7 @@ run(const char* prog_name) int saved_status = global_opts.verbose_status; global_opts.verbose_status = 0; lists_backedup = true; - waypt_backup(&wpt_ct_bak, &wpt_head_bak); + waypt_backup(&wpt_head_bak); route_backup(&rte_head_bak); track_backup(&trk_head_bak); @@ -378,7 +379,8 @@ run(const char* prog_name) cet_convert_deinit(); if (lists_backedup) { - waypt_restore(wpt_ct_bak, wpt_head_bak); + waypt_restore(wpt_head_bak); + delete wpt_head_bak; route_restore(rte_head_bak); delete rte_head_bak; track_restore(trk_head_bak); diff --git a/mapasia.cc b/mapasia.cc index 651648204..b13845120 100644 --- a/mapasia.cc +++ b/mapasia.cc @@ -20,12 +20,21 @@ */ +#include // for fabs +#include // for memset + +#include // for QDate +#include // for QDateTime +#include // for QString +#include // for QTime +#include // for UTC +#include // for foreach + #include "defs.h" -#include -#include -#include -#include -//#include "session.h" +#include "gbfile.h" // for gbfclose, gbfeof, gbfgetint32, gbfputint32, gbfread, gbfwrite, gbfile, gbfopen_le +#include "session.h" // for curr_session +#include "src/core/datetime.h" // for DateTime + #define MYNAME "mapasia" @@ -167,9 +176,7 @@ tr7_check_after_read_wpt_cb(const Waypoint* wpt) static void tr7_check_after_read_trailer_cb(const route_head* trk) { - queue* elem, *tmp; - QUEUE_FOR_EACH((queue*)&trk->waypoint_list, elem, tmp) { - Waypoint* wpt = reinterpret_cast(elem); + foreach (Waypoint* wpt, trk->waypoint_list) { if (speed_tmp == 0) { WAYPT_UNSET(wpt, speed); } diff --git a/mapsend.cc b/mapsend.cc index 262a2c91a..bebb844f9 100644 --- a/mapsend.cc +++ b/mapsend.cc @@ -18,12 +18,23 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */ +#include // for lround +#include // for sprintf +#include // for atoi +#include // for strncpy +#include + +#include // for QCharRef +#include // for QString +#include // for QTime +#include // for Q_UNUSED + #include "defs.h" -#include "magellan.h" #include "mapsend.h" -#include -#include -#include +#include "gbfile.h" // for gbfputint32, gbfgetint32, gbfgetdbl, gbfputdbl, gbfgetpstr, gbfwrite, gbfputpstr, gbfputc, gbfread, gbfclose, gbfgetc, gbfgetflt, gbfopen, gbfputflt, gbfile, gbfgetuint32, gbfopen_le, gbsize_t +#include "magellan.h" // for mag_find_token_from_descr, mag_find_descr_from_token +#include "src/core/datetime.h" // for DateTime + static gbfile* mapsend_file_in; static gbfile* mapsend_file_out; @@ -395,7 +406,6 @@ static void mapsend_track_hdr(const route_head* trk) * tremendously out of whack time/date wise. */ const char* verstring = "30"; - queue* elem, *tmp; mapsend_hdr hdr = {13, {'4','D','5','3','3','3','3','4',' ','M','S'}, {'3','0'}, ms_type_track, {0, 0, 0} }; @@ -428,10 +438,7 @@ static void mapsend_track_hdr(const route_head* trk) gbfputpstr(tname, mapsend_file_out); /* total nodes (waypoints) this track */ - int i = 0; - QUEUE_FOR_EACH(&trk->waypoint_list, elem, tmp) { - i++; - } + int i = trk->waypoint_list.count(); gbfputint32(i, mapsend_file_out); diff --git a/mapsource.cc b/mapsource.cc index 17cbcd58f..090c6edcd 100644 --- a/mapsource.cc +++ b/mapsource.cc @@ -25,17 +25,18 @@ #include // for atoi, rand, srand #include // for strcpy, memset, strlen, strcmp #include // for time_t +#include // for SEEK_CUR #include // for QChar #include // for QFile #include // for QList #include // for QString, operator== +#include // for foreach #include "defs.h" #include "garmin_tables.h" // for gt_find_icon_number_from_desc, MAPSOURCE, gt_find_desc_from_icon_number, GARMIN_SERIAL, PCX, garmin_formats_e #include "gbfile.h" // for gbfwrite, gbfread, gbfgetint32, gbfputint32, gbfseek, gbfputc, gbfgetc, gbfputdbl, gbfgetdbl, gbfclose, gbfeof, gbfile, gbftell, gbfgetcstr, gbfputs, gbfopen_le #include "jeeps/gpsmath.h" // for GPS_Math_Deg_To_Semi, GPS_Math_Semi_To_Deg -#include "queue.h" // for queue, QUEUE_FOR_EACH #include "src/core/datetime.h" // for DateTime @@ -1101,8 +1102,6 @@ mps_routehdr_w(gbfile* mps_file, int mps_ver, const route_head* rte) double maxalt=unknown_alt; double minalt=-unknown_alt; - queue* elem, *tmp; - prevRouteWpt = nullptr; /* clear the stateful flag used to know when the start of route wpts happens */ memset(zbuf, 0, sizeof(zbuf)); @@ -1111,9 +1110,9 @@ mps_routehdr_w(gbfile* mps_file, int mps_ver, const route_head* rte) unsigned int rte_datapoints = 0; int allWptNameLengths = 0; - if (rte->waypoint_list.next) { /* this test doesn't do what I want i.e test if this is a valid route - treat as a placeholder for now */ - QUEUE_FOR_EACH(&rte->waypoint_list, elem, tmp) { - Waypoint* testwpt = reinterpret_cast(elem); + //if (rte->waypoint_list.next) { /* this test doesn't do what I want i.e test if this is a valid route - treat as a placeholder for now */ + if (true) { + foreach (const Waypoint* testwpt, rte->waypoint_list) { if (rte_datapoints == 0) { uniqueValue = testwpt->GetCreationTime().toTime_t(); } @@ -1420,7 +1419,8 @@ mps_routetrlr_w(gbfile* mps_file, int mps_ver, const route_head* rte) (void)mps_ver; hdr[0] = 1; - if (rte->waypoint_list.next) { /* this test doesn't do what I want i.e test if this is a valid route - treat as a placeholder for now */ + //if (rte->waypoint_list.next) { /* this test doesn't do what I want i.e test if this is a valid route - treat as a placeholder for now */ + if (true) { gbfwrite(&value, 4, 1, mps_file); gbfwrite(hdr, 1, 1, mps_file); } @@ -1531,16 +1531,14 @@ mps_trackhdr_w(gbfile* mps_file, int mps_ver, const route_head* trk) char hdr[20]; time_t uniqueValue = 0; - queue* elem, *tmp; - (void)mps_ver; /* total nodes (waypoints) this track */ unsigned int trk_datapoints = 0; - if (trk->waypoint_list.next) { /* this test doesn't do what I want i.e test if this is a valid track - treat as a placeholder for now */ - QUEUE_FOR_EACH(&trk->waypoint_list, elem, tmp) { + //if (trk->waypoint_list.next) { /* this test doesn't do what I want i.e test if this is a valid track - treat as a placeholder for now */ + if (true) { + foreach (const Waypoint* testwpt, trk->waypoint_list) { if (trk_datapoints == 0) { - Waypoint* testwpt = reinterpret_cast(elem); uniqueValue = testwpt->GetCreationTime().toTime_t(); } trk_datapoints++; diff --git a/mmo.cc b/mmo.cc index f211e8cf9..24cc4367f 100644 --- a/mmo.cc +++ b/mmo.cc @@ -20,12 +20,30 @@ */ +#include // for isspace +#include // for errno +#include // for SEEK_CUR, fprintf, size_t, stdout +#include // for abort, strtol +#include +#include // for strcmp, strlen, memset, strchr, strncmp +#include + +#include // for QByteArray +#include // for operator==, QChar +#include // for QCharRef +#include // for QDateTime +#include // for QHash, QHash<>::const_iterator +#include // for QLatin1String +#include // for QString, operator== +#include // for CaseInsensitive +#include // for qAsConst, QAddConst<>::Type, foreach, Q_UNUSED + #include "defs.h" -#include -#include -#include -#include -#include +#include "cet.h" // for cet_ucs4_to_utf8, cet_utf8_to_ucs4 +#include "gbfile.h" // for gbfputc, gbfgetuint16, gbfgetc, gbfgetdbl, gbfgetuint32, gbfputflt, gbfputuint32, gbfgetint16, gbfputdbl, gbfputuint16, gbfclose, gbfread, gbfseek, gbfputint16, gbfwrite, gbfcopyfrom, gbfeof, gbfgetflt, gbfgetint32, gbfile, gbfopen, gbfrewind, gbsize_t +#include "session.h" // for curr_session, session_t +#include "src/core/datetime.h" // for DateTime + #define MYNAME "mmo" @@ -1270,7 +1288,6 @@ mmo_write_wpt_cb(const Waypoint* wpt) static void mmo_write_rte_head_cb(const route_head* rte) { - queue* elem, *tmp; time_t time = 0x7FFFFFFF; if (rte->rte_waypt_ct <= 0) { @@ -1279,8 +1296,7 @@ mmo_write_rte_head_cb(const route_head* rte) mmo_rte = rte; - QUEUE_FOR_EACH(&rte->waypoint_list, elem, tmp) { - Waypoint* wpt = reinterpret_cast(elem); + foreach (const Waypoint* wpt, rte->waypoint_list) { QDateTime t = wpt->GetCreationTime(); if ((t.isValid()) && (t.toTime_t() < time)) { time = t.toTime_t(); @@ -1301,8 +1317,6 @@ mmo_write_rte_head_cb(const route_head* rte) static void mmo_write_rte_tail_cb(const route_head* rte) { - queue* elem, *tmp; - if (rte->rte_waypt_ct <= 0) { return; } @@ -1323,8 +1337,7 @@ mmo_write_rte_tail_cb(const route_head* rte) } } - QUEUE_FOR_EACH(&rte->waypoint_list, elem, tmp) { - Waypoint* wpt = reinterpret_cast(elem); + foreach (const Waypoint* wpt, rte->waypoint_list) { int objid = mmo_get_objid(wpt); gbfputuint16(objid & 0x7FFF, fout); } diff --git a/netstumbler.cc b/netstumbler.cc index 4645f7ab4..61df8a844 100644 --- a/netstumbler.cc +++ b/netstumbler.cc @@ -20,12 +20,20 @@ */ +#include // for isspace +#include // for snprintf +#include // for atoi, atof, qsort, strtol +#include // for strcpy, strlen, memset, strncmp, strstr +#include // for mktime + +#include // for QString +#include // for foreach + #include "defs.h" -#include "cet_util.h" -#include "csv_util.h" -#include -#include -#include +#include "cet_util.h" // for cet_convert_init +#include "csv_util.h" // for csv_lineparse +#include "gbfile.h" // for gbfclose, gbfgetstr, gbfopen, gbfile + static gbfile* file_in; static char* nseicon = nullptr; @@ -298,18 +306,11 @@ fix_netstumbler_dupes() htable_t* bh = htable; int i = 0; -#if NEWQ // Why, oh, why is this format running over the entire waypoint list and // modifying it? This seems wrong. - extern QList waypt_list; - foreach(Waypoint* waypointp, waypt_list) { + extern WaypointList* global_waypoint_list; + foreach(Waypoint* waypointp, *global_waypoint_list) { bh->wpt = waypointp; -#else - queue* elem, *tmp; - extern queue waypt_head; - QUEUE_FOR_EACH(&waypt_head, elem, tmp) { - bh->wpt = reinterpret_cast(elem); -#endif QString snptr = bh->wpt->shortname; QString tmp_sn = snptr.toLower(); bh->crc = get_crc32(CSTR(tmp_sn), tmp_sn.length()); diff --git a/nmea.cc b/nmea.cc index 810d9833c..14d414a8f 100644 --- a/nmea.cc +++ b/nmea.cc @@ -26,6 +26,7 @@ #include // for atoi, atof #include // for strncmp, memset, strlen, strchr, strstr, strrchr #include // for gmtime +#include // for operator!=, reverse_iterator #include // for QByteArray #include // for QChar, operator==, operator!= @@ -43,7 +44,6 @@ #include "gbfile.h" // for gbfprintf, gbfflush, gbfclose, gbfopen, gbfgetstr, gbfile #include "gbser.h" // for gbser_set_speed, gbser_flush, gbser_read_line, gbser_deinit, gbser_init, gbser_write #include "jeeps/gpsmath.h" // for GPS_Lookup_Datum_Index, GPS_Math_Known_Datum_To_WGS84_M -#include "queue.h" // for queue, QUEUE_FOR_EACH, QUEUE_LAST #include "src/core/datetime.h" // for DateTime #include "src/core/logging.h" // for Warning #include "strptime.h" // for strptime @@ -879,7 +879,6 @@ nmea_fix_timestamps(route_head* track) } if (tm.tm_year == 0) { - queue* elem, *temp; Waypoint* prev = nullptr; if (optdate == nullptr) { @@ -890,8 +889,7 @@ nmea_fix_timestamps(route_head* track) } time_t delta_tm = mkgmtime(&opt_tm); - QUEUE_FOR_EACH(&track->waypoint_list, elem, temp) { - Waypoint* wpt = reinterpret_cast(elem); + foreach (Waypoint* wpt, track->waypoint_list) { wpt->creation_time += delta_tm; if ((prev != nullptr) && (prev->creation_time > wpt->creation_time)) { @@ -910,8 +908,8 @@ nmea_fix_timestamps(route_head* track) /* go backward through the track and complete timestamps */ - for (queue* elem = QUEUE_LAST(&track->waypoint_list); elem != &track->waypoint_list; elem=elem->prev) { - Waypoint* wpt = reinterpret_cast(elem); + for (auto it = track->waypoint_list.crbegin(); it != track->waypoint_list.crend(); ++it) { + Waypoint* wpt = *it; if (wpt->wpt_flags.fmt_use != 0) { wpt->wpt_flags.fmt_use = 0; /* reset flag */ diff --git a/pocketfms_fp.cc b/pocketfms_fp.cc index d45779cfd..58d926fae 100644 --- a/pocketfms_fp.cc +++ b/pocketfms_fp.cc @@ -19,10 +19,13 @@ */ +#include // for QString +#include // for QStringRef +#include // for QXmlStreamAttributes #include "defs.h" -#include "xmlgeneric.h" -#include +#include "xmlgeneric.h" // for cb_cdata, xg_callback, xg_string, cb_start, cb_end, xg_cb_type, xml_deinit, xml_init, xml_read, xg_tag_mapping + static int isFirst = 1; static route_head* route = nullptr; @@ -65,8 +68,8 @@ static void rd_deinit() { if (route != nullptr) { - Waypoint* head = reinterpret_castQUEUE_FIRST(&route->waypoint_list); - Waypoint* tail = reinterpret_castQUEUE_LAST(&route->waypoint_list); + Waypoint* head = route->waypoint_list.front(); + Waypoint* tail = route->waypoint_list.back(); if (head != nullptr) { route->rte_name = head->shortname; } diff --git a/polygon.cc b/polygon.cc index 75b0e77e1..c9c4ab0e2 100644 --- a/polygon.cc +++ b/polygon.cc @@ -18,10 +18,17 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */ + +#include // for sscanf +#include // for strchr, strlen, strspn + +#include // for foreach + #include "defs.h" -#include "filterdefs.h" +#include "filterdefs.h" // for global_waypoint_list #include "polygon.h" -#include +#include "gbfile.h" // for gbfclose, gbfgetstr, gbfopen, gbfile + #if FILTERS_ENABLED #define MYNAME "Polygon filter" @@ -215,8 +222,6 @@ void PolygonFilter::polytest(double lat1, double lon1, void PolygonFilter::process() { - queue* elem, * tmp; - Waypoint* waypointp; extra_data* ed; int fileline = 0; int first = 1; @@ -248,12 +253,7 @@ void PolygonFilter::process() fileline); } else if (lat1 != BADVAL && lon1 != BADVAL && lat2 != BADVAL && lon2 != BADVAL) { -#if NEWQ - foreach (Waypoint* waypointp, waypt_list) { -#else - QUEUE_FOR_EACH(&waypt_head, elem, tmp) { - waypointp = reinterpret_cast(elem); -#endif + foreach (Waypoint* waypointp, *global_waypoint_list) { if (waypointp->extra_data) { ed = (extra_data*) waypointp->extra_data; } else { @@ -297,12 +297,7 @@ void PolygonFilter::process() } gbfclose(file_in); -#if NEWQ - foreach (Waypoint* wp, waypt_list) { -#else - QUEUE_FOR_EACH(&waypt_head, elem, tmp) { - Waypoint* wp = reinterpret_cast(elem); -#endif + foreach (Waypoint* wp, *global_waypoint_list) { ed = (extra_data*) wp->extra_data; wp->extra_data = nullptr; if (ed) { diff --git a/position.cc b/position.cc index 6e6cf4c73..47509de28 100644 --- a/position.cc +++ b/position.cc @@ -19,12 +19,15 @@ */ +#include // for fabs +#include // for strtod + +#include // for foreach + #include "defs.h" #include "filterdefs.h" -#include "grtcirc.h" +#include "grtcirc.h" // for RAD, gcdist, radtomiles #include "position.h" -#include -#include #if FILTERS_ENABLED @@ -39,22 +42,16 @@ double PositionFilter::gc_distance(double lat1, double lon1, double lat2, double } /* tear through a waypoint queue, processing points by distance */ -void PositionFilter::position_runqueue(queue* q, int nelems, int qtype) +void PositionFilter::position_runqueue(WaypointList* waypt_list, int nelems, int qtype) { - queue* elem, * tmp; double dist, diff_time; int i = 0, anyitem; Waypoint** comp = (Waypoint**) xcalloc(nelems, sizeof(*comp)); int* qlist = (int*) xcalloc(nelems, sizeof(*qlist)); -#if NEWQ - foreach (Waypoint* waypointp, waypt_list) { + foreach (Waypoint* waypointp, *waypt_list) { comp[i] = waypointp; -#else - QUEUE_FOR_EACH(q, elem, tmp) { - comp[i] = reinterpret_cast(elem); -#endif qlist[i] = 0; i++; } @@ -137,7 +134,7 @@ void PositionFilter::position_process_any_route(const route_head* rh, int type) if (i) { cur_rte = const_cast(rh); - position_runqueue(const_cast(&rh->waypoint_list), i, type); + position_runqueue(&cur_rte->waypoint_list, i, type); cur_rte = nullptr; } @@ -161,7 +158,7 @@ void PositionFilter::process() int i = waypt_count(); if (i) { - position_runqueue(&waypt_head, i, wptdata); + position_runqueue(global_waypoint_list, i, wptdata); } route_disp_all(position_process_rte_f, nullptr, nullptr); diff --git a/position.h b/position.h index e7477aa83..4c90107f6 100644 --- a/position.h +++ b/position.h @@ -24,7 +24,6 @@ #include "defs.h" // for route_head (ptr only), ARG_NOMINMAX, ARGTYPE_FLOAT #include "filter.h" // for Filter -#include "queue.h" // for queue #if FILTERS_ENABLED @@ -70,7 +69,7 @@ private: }; double gc_distance(double lat1, double lon1, double lat2, double lon2); - void position_runqueue(queue* q, int nelems, int qtype); + void position_runqueue(WaypointList* waypt_list, int nelems, int qtype); void position_process_any_route(const route_head* rh, int type); void position_process_rte(const route_head* rh); void position_process_trk(const route_head* rh); diff --git a/psitrex.cc b/psitrex.cc index d8b77d70b..d373bd884 100644 --- a/psitrex.cc +++ b/psitrex.cc @@ -19,11 +19,22 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */ +#include // for isspace +#include // for sscanf, EOF, size_t +#include // for atof, atoi +#include // for strcmp, strlen, strcpy +#include // for gmtime + +#include // for QChar +#include // for QLatin1String +#include // for QString +#include // for foreach, uint + #include "defs.h" -#include "garmin_tables.h" -#include -#include -#include +#include "garmin_tables.h" // for gt_find_desc_from_icon_number, gt_find_icon_number_from_desc, PCX +#include "gbfile.h" // for gbfprintf, gbfeof, gbfile, gbfgetc, gbfclose, gbfgets, gbfopen, gbfputs +#include "src/core/datetime.h" // for DateTime + #define MYNAME "PSITREX" @@ -451,14 +462,13 @@ psit_routehdr_w(gbfile* psit_file, const route_head* rte) QString rname; /* total nodes (waypoints) this route */ - if (rte->waypoint_list.next) { + //if (rte->waypoint_list.next) { + if (true) { // this test doesn't do what I w ant i.e test if this is a valid // route - treat as a placeholder for now . time_t uniqueValue = 0; unsigned int rte_datapoints = 0; - queue *elem, *tmp; - QUEUE_FOR_EACH(&rte->waypoint_list, elem, tmp) { - Waypoint* testwpt = reinterpret_cast(elem); + foreach (const Waypoint* testwpt, rte->waypoint_list) { if (rte_datapoints == 0) { uniqueValue = testwpt->GetCreationTime().toTime_t(); } @@ -591,16 +601,14 @@ psit_trackhdr_w(gbfile* psit_file, const route_head* trk) QString tname; time_t uniqueValue = 0; - queue* elem, *tmp; - if (psit_track_state == 2) { /* total nodes (waypoints) this track */ - if (trk->waypoint_list.next) { /* this test doesn't do what I want i.e test if this is a valid track - treat as a placeholder for now */ + //if (trk->waypoint_list.next) { /* this test doesn't do what I want i.e test if this is a valid track - treat as a placeholder for now */ + if (true) { unsigned int trk_datapoints = 0; - QUEUE_FOR_EACH(&trk->waypoint_list, elem, tmp) { + foreach (const Waypoint* testwpt, trk->waypoint_list) { if (trk_datapoints == 0) { - Waypoint* testwpt = reinterpret_cast(elem); uniqueValue = testwpt->GetCreationTime().toTime_t(); } trk_datapoints++; diff --git a/radius.cc b/radius.cc index 0a68b49c5..4eb8c8dda 100644 --- a/radius.cc +++ b/radius.cc @@ -18,12 +18,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */ + +#include // for atof, atoi, qsort, strtod + +#include // for QString +#include // for foreach + #include "defs.h" #include "filterdefs.h" -#include "grtcirc.h" #include "radius.h" -#include -#include +#include "grtcirc.h" // for RAD, gcdist, radtomiles #if FILTERS_ENABLED @@ -56,18 +60,10 @@ int RadiusFilter::dist_comp(const void* a, const void* b) void RadiusFilter::process() { -#if !NEWQ - queue* elem, * tmp; -#endif Waypoint** comp; int i, wc; route_head* rte_head = nullptr; -#if NEWQ - foreach (Waypoint* waypointp, waypt_list) { -#else - QUEUE_FOR_EACH(&waypt_head, elem, tmp) { - Waypoint* waypointp = reinterpret_cast(elem); -#endif + foreach (Waypoint* waypointp, *global_waypoint_list) { double dist = gc_distance(waypointp->latitude, waypointp->longitude, home_pos->latitude, @@ -99,12 +95,7 @@ void RadiusFilter::process() * for qsort. */ -#if NEWQ - foreach (Waypoint* wp, waypt_list) { -#else - QUEUE_FOR_EACH(&waypt_head, elem, tmp) { - Waypoint* wp = reinterpret_cast(elem); -#endif + foreach (Waypoint* wp, *global_waypoint_list) { comp[i] = wp; waypt_del(wp); i++; diff --git a/reverse_route.cc b/reverse_route.cc index 3f85066c2..64709a56e 100644 --- a/reverse_route.cc +++ b/reverse_route.cc @@ -18,6 +18,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */ +#include // for reverse + +#include // for QList<>::iterator + #include "defs.h" #include "filterdefs.h" #include "reverse_route.h" @@ -44,10 +48,7 @@ void ReverseRouteFilter::reverse_route_head(const route_head* rte_hd) { /* Cast away const-ness */ auto rh = const_cast(rte_hd); - queue* elem, *tmp; - QUEUE_FOR_EACH(&rh->waypoint_list, elem, tmp) { - ENQUEUE_HEAD(&rh->waypoint_list, dequeue(elem)); - } + std::reverse(rh->waypoint_list.begin(), rh->waypoint_list.end()); prev_new_trkseg = 1; } diff --git a/route.cc b/route.cc index 81b7ff398..8ef484bb0 100644 --- a/route.cc +++ b/route.cc @@ -17,18 +17,22 @@ */ +#include // for assert +#include // for nullptr_t +#include // for sort +#include + +#include // for QDateTime +#include // for QList<>::iterator +#include // for QString +#include // for foreach + #include "defs.h" #include "grtcirc.h" // for RAD, gcdist, heading_true_degrees, radtometers -#include "queue.h" // for dequeue, queue, QUEUE_FOR_EACH, QUEUE_EMPTY, ENQUEUE_HEAD, ENQUEUE_TAIL, QUEUE_INIT, QUEUE_LAST, QUEUE_NEXT #include "session.h" // for curr_session, session_t (ptr only) #include "src/core/datetime.h" // for DateTime #include "src/core/optional.h" // for optional, operator>, operator< -#include // for QDateTime -#include // for QList<>::iterator -#include // for QString -#include // for foreach -#include // for sort -#include // for nullptr_t + RouteList* global_route_list; RouteList* global_track_list; @@ -112,7 +116,7 @@ route_add_wpt(route_head* rte, Waypoint* wpt, const QString& namepart, int numbe // First point in a route is always a new segment. // This improves compatibility when reading from // segment-unaware formats. - if (QUEUE_EMPTY(&rte->waypoint_list)) { + if (rte->waypoint_list.empty()) { wpt->wpt_flags.new_trkseg = 1; } @@ -125,7 +129,7 @@ track_add_wpt(route_head* rte, Waypoint* wpt, const QString& namepart, int numbe // First point in a track is always a new segment. // This improves compatibility when reading from // segment-unaware formats. - if (QUEUE_EMPTY(&rte->waypoint_list)) { + if (rte->waypoint_list.empty()) { wpt->wpt_flags.new_trkseg = 1; } @@ -256,8 +260,7 @@ track_sort(RouteList::Compare cmp) computed_trkdata track_recompute(const route_head* trk) { Waypoint first; - Waypoint* prev = &first; - queue* elem, *tmp; + const Waypoint* prev = &first; int tkpt = 0; int pts_hrt = 0; double tot_hrt = 0.0; @@ -269,8 +272,7 @@ computed_trkdata track_recompute(const route_head* trk) // first.longitude = 0; // first.creation_time = 0; - QUEUE_FOR_EACH(&trk->waypoint_list, elem, tmp) { - auto thisw = reinterpret_cast(elem); + foreach (Waypoint* thisw, trk->waypoint_list) { /* * gcdist and heading want radians, not degrees. @@ -383,12 +385,11 @@ route_head::route_head() : line_width(-1), session(curr_session()) { - QUEUE_INIT(&waypoint_list); }; route_head::~route_head() { - waypt_flush(&waypoint_list); + waypoint_list.flush(); if (fs) { fs_chain_destroy(fs); } @@ -414,6 +415,7 @@ RouteList::del_head(route_head* rte) { waypt_ct -= rte->rte_waypt_ct; const int idx = this->indexOf(rte); + assert(idx >= 0); removeAt(idx); delete rte; } @@ -422,6 +424,7 @@ void RouteList::insert_head(route_head* rte, route_head* predecessor) { const int idx = this->indexOf(predecessor); + assert(idx >= 0); this->insert(idx + 1, rte); } @@ -432,25 +435,18 @@ RouteList::insert_head(route_head* rte, route_head* predecessor) void RouteList::add_wpt(route_head* rte, Waypoint* wpt, bool synth, const QString& namepart, int number_digits) { - ENQUEUE_TAIL(&rte->waypoint_list, &wpt->Q); rte->rte_waypt_ct++; /* waypoints in this route */ ++waypt_ct; - if (synth && wpt->shortname.isEmpty()) { - wpt->shortname = QString("%1%2").arg(namepart).arg(waypt_ct, number_digits, 10, QChar('0')); - wpt->wpt_flags.shortname_is_synthetic = 1; + rte->waypoint_list.add_rte_waypt(waypt_ct, wpt, synth, namepart, number_digits); + if ((this == global_route_list) || (this == global_track_list)) { + update_common_traits(wpt); } - update_common_traits(wpt); } void RouteList::del_wpt(route_head* rte, Waypoint* wpt) { - if (wpt->wpt_flags.new_trkseg && wpt != reinterpret_castQUEUE_LAST(&rte->waypoint_list)) { - auto wpt_next = reinterpret_castQUEUE_NEXT(&wpt->Q); - wpt_next->wpt_flags.new_trkseg = 1; - } - wpt->wpt_flags.new_trkseg = 0; - dequeue(&wpt->Q); + rte->waypoint_list.del_rte_waypt(wpt); rte->rte_waypt_ct--; --waypt_ct; } @@ -474,18 +470,15 @@ RouteList::common_disp_session(const session_t* se, route_hdr rh, route_trl rt, void RouteList::flush() { - foreach (route_head* rte, *this) { - delete rte; + while (!isEmpty()) { + delete takeFirst(); } - clear(); waypt_ct = 0; } void RouteList::copy(RouteList** dst) const { - queue* elem2, *tmp2; - if (*dst == nullptr) { *dst = new RouteList; } @@ -499,8 +492,8 @@ RouteList::copy(RouteList** dst) const rte_new->fs = fs_chain_copy(rte_old->fs); rte_new->rte_num = rte_old->rte_num; (*dst)->add_head(rte_new); - QUEUE_FOR_EACH(&rte_old->waypoint_list, elem2, tmp2) { - (*dst)->add_wpt(rte_new, new Waypoint(*reinterpret_cast(elem2)), false, RPT, 3); + foreach (const Waypoint* old_wpt, rte_old->waypoint_list) { + (*dst)->add_wpt(rte_new, new Waypoint(*old_wpt), false, RPT, 3); } } } @@ -529,4 +522,3 @@ void RouteList::sort(Compare cmp) { std::sort(begin(), end(), cmp); } - diff --git a/sort.cc b/sort.cc index 1c636411b..f8d7b2edf 100644 --- a/sort.cc +++ b/sort.cc @@ -18,48 +18,37 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */ + +#include // for QDateTime +#include // for operator<, QString + #include "defs.h" +#include "src/core/datetime.h" // for DateTime #include "filterdefs.h" #include "sort.h" -#include // for QString -#include // for abort #if FILTERS_ENABLED #define MYNAME "sort" -template -inline int sgn(T v) + +bool SortFilter::sort_comp_wpt_by_description(const Waypoint* a, const Waypoint* b) { -// Returns 1 if v > 0, -1 if v < 0, and 0 if v is zero - return (v > T(0)) - (v < T(0)); + return a->description < b->description; } -template -inline int cmp(T a, T b) +bool SortFilter::sort_comp_wpt_by_gcid(const Waypoint* a, const Waypoint* b) { -// Returns 1 if a > b, -1 if a < b, and 0 if a = b -// note possible overflow in computing sgn(a-b) is avoided. - return (a > b) - (a < b); + return a->gc_data->id < b->gc_data->id; } -int SortFilter::sort_comp_wpt(const queue* a, const queue* b) +bool SortFilter::sort_comp_wpt_by_shortname(const Waypoint* a, const Waypoint* b) { - const Waypoint* x1 = reinterpret_cast(a); - const Waypoint* x2 = reinterpret_cast(b); - - switch (wpt_sort_mode) { - case SortModeWpt::description: - return x1->description.compare(x2->description); - case SortModeWpt::gcid: - return cmp(x1->gc_data->id, x2->gc_data->id); - case SortModeWpt::shortname: - return x1->shortname.compare(x2->shortname); - case SortModeWpt::time: - return sgn(x2->GetCreationTime().msecsTo(x1->GetCreationTime())); - default: - abort(); - return 0; /* Internal caller error. */ - } + return a->shortname < b->shortname; +} + +bool SortFilter::sort_comp_wpt_by_time(const Waypoint* a, const Waypoint* b) +{ + return a->GetCreationTime() < b->GetCreationTime(); } bool SortFilter::sort_comp_rh_by_description(const route_head* a, const route_head* b) @@ -74,21 +63,30 @@ bool SortFilter::sort_comp_rh_by_name(const route_head* a, const route_head* b) bool SortFilter::sort_comp_rh_by_number(const route_head* a, const route_head* b) { - return a->rte_num < b->rte_num; -} - -int SortFilter::SortCompWptFunctor::operator()(const queue* a, const queue* b) -{ - return that->sort_comp_wpt(a, b); + return a->rte_num < b->rte_num; } void SortFilter::process() { - SortCompWptFunctor sort_comp_wpt_f(*this); - if (wpt_sort_mode != SortModeWpt::none) { - sortqueue(&waypt_head, sort_comp_wpt_f); + switch (wpt_sort_mode) { + case SortModeWpt::description: + waypt_sort(sort_comp_wpt_by_description); + break; + case SortModeWpt::gcid: + waypt_sort(sort_comp_wpt_by_gcid); + break; + case SortModeWpt::shortname: + waypt_sort(sort_comp_wpt_by_shortname); + break; + case SortModeWpt::time: + waypt_sort(sort_comp_wpt_by_time); + break; + default: + fatal(MYNAME ": unknown waypoint sort mode."); + } } + if (rte_sort_mode != SortModeRteHd::none) { switch (rte_sort_mode) { case SortModeRteHd::description: diff --git a/sort.h b/sort.h index b724ecc32..d6e030b3e 100644 --- a/sort.h +++ b/sort.h @@ -24,7 +24,6 @@ #include "defs.h" // for ARGTYPE_BOOL, ARG_NOMINMAX, arglist_t, ARG_TERMI... #include "filter.h" // for Filter -#include "queue.h" // for queue #if FILTERS_ENABLED @@ -107,21 +106,14 @@ private: ARG_TERMINATOR }; - int sort_comp_wpt(const queue* a, const queue* b); + static bool sort_comp_wpt_by_description(const Waypoint* a, const Waypoint* b); + static bool sort_comp_wpt_by_gcid(const Waypoint* a, const Waypoint* b); + static bool sort_comp_wpt_by_shortname(const Waypoint* a, const Waypoint* b); + static bool sort_comp_wpt_by_time(const Waypoint* a, const Waypoint* b); static bool sort_comp_rh_by_description(const route_head* a, const route_head* b); static bool sort_comp_rh_by_name(const route_head* a, const route_head* b); static bool sort_comp_rh_by_number(const route_head* a, const route_head* b); - class SortCompWptFunctor - { - public: - explicit SortCompWptFunctor(SortFilter& obj) : that(&obj) {} - int operator()(const queue* a, const queue* b); - - private: - SortFilter* that; - }; - }; #endif // FILTERS_ENABLED #endif // SORT_H_INCLUDED_ diff --git a/stackfilter.cc b/stackfilter.cc index 3721ab25a..d826c5e29 100644 --- a/stackfilter.cc +++ b/stackfilter.cc @@ -19,10 +19,11 @@ */ +#include // for atoi + #include "defs.h" #include "filterdefs.h" #include "stackfilter.h" -#include #if FILTERS_ENABLED @@ -31,23 +32,18 @@ void StackFilter::process() { stack_elt* tmp_elt = nullptr; - queue* elem = nullptr; - queue* tmp = nullptr; - queue tmp_queue; + WaypointList* waypt_list_ptr; RouteList* route_list_ptr; if (opt_push) { tmp_elt = new stack_elt; - - QUEUE_MOVE(&(tmp_elt->waypts), &waypt_head); - tmp_elt->waypt_ct = waypt_count(); - set_waypt_count(0); tmp_elt->next = stack; stack = tmp_elt; - if (opt_copy) { - QUEUE_FOR_EACH(&(stack->waypts), elem, tmp) { - waypt_add(new Waypoint(*reinterpret_cast(elem))); - } + + waypt_list_ptr = &(tmp_elt->waypts); + waypt_backup(&waypt_list_ptr); + if (!opt_copy) { + waypt_flush_all(); } route_list_ptr = &(tmp_elt->routes); @@ -68,22 +64,18 @@ void StackFilter::process() fatal(MYNAME ": stack empty\n"); } if (opt_append) { - QUEUE_FOR_EACH(&(stack->waypts), elem, tmp) { - waypt_add(reinterpret_cast(elem)); - } + waypt_append(&(stack->waypts)); + stack->waypts.flush(); route_append(&(stack->routes)); stack->routes.flush(); track_append(&(stack->tracks)); stack->tracks.flush(); } else if (opt_discard) { - waypt_flush(&(stack->waypts)); + stack->waypts.flush(); stack->routes.flush(); stack->tracks.flush(); } else { - waypt_flush(&waypt_head); - QUEUE_MOVE(&(waypt_head), &(stack->waypts)); - set_waypt_count(stack->waypt_ct); - + waypt_restore(&(stack->waypts)); route_restore(&(stack->routes)); track_restore(&(stack->tracks)); } @@ -99,12 +91,8 @@ void StackFilter::process() tmp_elt = tmp_elt->next; swapdepth--; } - QUEUE_MOVE(&tmp_queue, &(tmp_elt->waypts)); - QUEUE_MOVE(&(tmp_elt->waypts), &waypt_head); - QUEUE_MOVE(&waypt_head, &tmp_queue); - unsigned int tmp_count = waypt_count(); - set_waypt_count(tmp_elt->waypt_ct); - tmp_elt->waypt_ct = tmp_count; + + waypt_swap(tmp_elt->waypts); route_swap(tmp_elt->routes); @@ -165,7 +153,7 @@ void StackFilter::exit() "check command line for mistakes\n"); } while (stack) { - waypt_flush(&(stack->waypts)); + stack->waypts.flush(); stack->routes.flush(); stack->tracks.flush(); tmp_elt = stack; diff --git a/stackfilter.h b/stackfilter.h index 2e88cd785..81dc038ec 100644 --- a/stackfilter.h +++ b/stackfilter.h @@ -24,7 +24,6 @@ #include "defs.h" // for ARGTYPE_BOOL, ARG_NOMINMAX, ARGTYPE_BEGIN_EXCL #include "filter.h" // for Filter -#include "queue.h" // for queue #if FILTERS_ENABLED @@ -93,18 +92,11 @@ private: ARG_TERMINATOR }; - class stack_elt + struct stack_elt { - public: - stack_elt() - { - QUEUE_INIT(&waypts); - } - - queue waypts; + WaypointList waypts; RouteList routes; RouteList tracks; - unsigned int waypt_ct{0}; stack_elt* next{nullptr}; }; stack_elt* stack = nullptr; diff --git a/tomtom.cc b/tomtom.cc index 70830787f..f175bbcc3 100644 --- a/tomtom.cc +++ b/tomtom.cc @@ -37,11 +37,16 @@ description string beyond the NUL terminator. -- Ron Parker, 17 July 2006 */ +#include // for printf, snprintf, SEEK_CUR, EOF +#include // for qsort +#include // for strlen + +#include // for QString +#include // for foreach #include "defs.h" -#include -#include // sprintf -#include // qsort +#include "gbfile.h" // for gbfgetint32, gbfputint32, gbfclose, gbfgetc, gbfputc, gbfseek, gbfile, gbfeof, gbfread, gbftell, gbfwrite, gbfopen_le + #define MYNAME "TomTom" @@ -423,12 +428,7 @@ data_write() { int ct = waypt_count(); struct hdr* htable, *bh; -#if NEWQ - extern QList waypt_list; -#else - queue* elem, *tmp; - extern queue waypt_head; -#endif + extern WaypointList* global_waypoint_list; double minlon = 200; double maxlon = -200; double minlat = 200; @@ -438,13 +438,8 @@ data_write() htable = (struct hdr*) xmalloc(ct * sizeof(*htable)); bh = htable; -#if NEWQ // Iterate with waypt_disp_all? - foreach(Waypoint* waypointp, waypt_list) { -#else - QUEUE_FOR_EACH(&waypt_head, elem, tmp) { - Waypoint* waypointp = reinterpret_cast(elem); -#endif + foreach(Waypoint* waypointp, *global_waypoint_list) { bh->wpt = waypointp; if (waypointp->longitude > maxlon) { maxlon = waypointp->longitude; diff --git a/tpo.cc b/tpo.cc index 2cff68ee3..4db52b0bc 100644 --- a/tpo.cc +++ b/tpo.cc @@ -70,15 +70,24 @@ 3.x "recreation" */ +#include // for assert +#include // for cos, sqrt +#include // for printf, sprintf, SEEK_CUR, SEEK_SET +#include +#include // for strncmp, strlen, memset +#include // for vector + +#include // for QByteArray +#include // for operator==, QChar +#include // for QCharRef +#include // for QScopedArrayPointer +#include // for QString +#include // for qPrintable, Q_UNUSED #include "defs.h" -#include "jeeps/gpsmath.h" /* for datum conversions */ -#include // Wish we could use c++11... -#include -#include -#include -#include -#include +#include "gbfile.h" // for gbfread, gbfgetc, gbfgetint32, gbfwrite, gbfputint16, gbfseek, gbfgetdbl, gbfgetint16, gbfputdbl, gbfclose, gbfputint32, gbfile, gbfopen_le, gbfgetuint16 +#include "jeeps/gpsmath.h" // for GPS_Math_WGS84LatLonH_To_XYZ, GPS_Math_WGS84_To_Known_Datum_M, GPS_Math_Deg_To_Rad, GPS_Math_Known_Datum_To_WGS84_M + #define MYNAME "TPO" @@ -1614,7 +1623,7 @@ tpo_track_hdr(const route_head* rte) unsigned char unknown1[] = { 0xFF, 0x00, 0x00, 0x00 }; unsigned char bounding_box[8] = { 0x00, 0x80, 0x00, 0x80, 0xFF, 0x7F, 0xFF, 0x7F }; - Waypoint* first_track_waypoint = reinterpret_castQUEUE_FIRST(&rte->waypoint_list); + Waypoint* first_track_waypoint = rte->waypoint_list.front(); /* zoom level 1-5 visibility flags */ gbfwrite(visibility_flags, 1, sizeof(visibility_flags), tpo_file_out); diff --git a/trackfilter.cc b/trackfilter.cc index 421b079c2..dc15e6923 100644 --- a/trackfilter.cc +++ b/trackfilter.cc @@ -22,13 +22,16 @@ #undef TRACKF_DBG -#include "defs.h" -#include "filterdefs.h" -#include "queue.h" // for queue, QUEUE_FOR_EACH, QUEUE_FIRST, QUEUE_LAST, QUEUE_NEXT -#include "grtcirc.h" // for RAD, gcdist, heading_true_degrees, radtometers, radtomiles -#include "strptime.h" -#include "trackfilter.h" -#include "src/core/datetime.h" // for DateTime +#include // for assert +#include // for nan +#include // for printf +#include // for abs +#include // for strlen, strchr, strcmp +#include // for gmtime, strftime +#include // for next + +#include // for sort, stable_sort + #include // for QByteArray #include // for QChar #include // for QDate @@ -36,20 +39,21 @@ #ifdef TRACKF_DBG #include #endif -#include // for QList<>::iterator, QList -#include // for qint64, qPrintable +#include // for QList<>::iterator, QList, QList<>::const_iterator #include // for QRegExp, QRegExp::WildcardUnix #include // for QRegularExpression, QRegularExpression::CaseInsensitiveOption, QRegularExpression::PatternOptions #include // for QRegularExpressionMatch #include // for QString #include // for UTC, CaseInsensitive -#include // for sort, stable_sort -#include // for assert -#include // for nan -#include // for printf -#include // for abs -#include // for strlen, strchr, strcmp -#include // for gmtime, strftime +#include // for qAsConst, foreach, qPrintable, QAddConst<>::Type, qint64 + +#include "defs.h" +#include "filterdefs.h" +#include "trackfilter.h" + +#include "grtcirc.h" // for RAD, gcdist, radtometers, heading_true_degrees +#include "src/core/datetime.h" // for DateTime + #if FILTERS_ENABLED || MINIMAL_FILTERS #define MYNAME "trackfilter" @@ -153,27 +157,25 @@ fix_type TrackFilter::trackfilter_parse_fix(int* nsats) QDateTime TrackFilter::trackfilter_get_first_time(const route_head* track) { - if (QUEUE_EMPTY(&track->waypoint_list)) { + if (track->waypoint_list.empty()) { return QDateTime(); } else { - return reinterpret_cast(QUEUE_FIRST(&track->waypoint_list))->GetCreationTime(); + return track->waypoint_list.front()->GetCreationTime(); } } QDateTime TrackFilter::trackfilter_get_last_time(const route_head* track) { - if (QUEUE_EMPTY(&track->waypoint_list)) { + if (track->waypoint_list.empty()) { return QDateTime(); } else { - return reinterpret_cast(QUEUE_LAST(&track->waypoint_list))->GetCreationTime(); + return track->waypoint_list.back()->GetCreationTime(); } } void TrackFilter::trackfilter_fill_track_list_cb(const route_head* track) /* callback for track_disp_all */ { - queue* elem, *tmp; - if (track->rte_waypt_ct == 0) { track_del_head(const_cast(track)); return; @@ -181,8 +183,7 @@ void TrackFilter::trackfilter_fill_track_list_cb(const route_head* track) /* ca if (opt_name != nullptr) { if (!QRegExp(opt_name, Qt::CaseInsensitive, QRegExp::WildcardUnix).exactMatch(track->rte_name)) { - QUEUE_FOR_EACH(&track->waypoint_list, elem, tmp) { - auto wpt = reinterpret_cast(elem); + foreach (Waypoint* wpt, track->waypoint_list) { track_del_wpt(const_cast(track), wpt); delete wpt; } @@ -191,10 +192,9 @@ void TrackFilter::trackfilter_fill_track_list_cb(const route_head* track) /* ca } } - Waypoint* prev = nullptr; + const Waypoint* prev = nullptr; - QUEUE_FOR_EACH(&track->waypoint_list, elem, tmp) { - auto wpt = reinterpret_cast(elem); + foreach (const Waypoint* wpt, track->waypoint_list) { if (!(opt_merge && opt_discard) && need_time && (!wpt->creation_time.isValid())) { fatal(MYNAME "-init: Found track point at %f,%f without time!\n", wpt->latitude, wpt->longitude); @@ -263,7 +263,7 @@ void TrackFilter::trackfilter_pack_init_rte_name(route_head* track, const QDateT if (track->rte_waypt_ct == 0) { dt = default_time; } else { - auto wpt = reinterpret_castQUEUE_FIRST(&track->waypoint_list); + auto wpt = track->waypoint_list.front(); dt = wpt->GetCreationTime(); } time_t t = dt.toTime_t(); @@ -320,9 +320,7 @@ void TrackFilter::trackfilter_pack() while (track_list.size() > 1) { route_head* curr = track_list.takeAt(1); - queue* elem, *tmp; - QUEUE_FOR_EACH(&curr->waypoint_list, elem, tmp) { - auto wpt = reinterpret_cast(elem); + foreach (Waypoint* wpt, curr->waypoint_list) { track_del_wpt(curr, wpt); track_add_wpt(master, wpt); } @@ -347,9 +345,7 @@ void TrackFilter::trackfilter_merge() auto it = track_list.begin(); while (it != track_list.end()) { /* put all points into temp buffer */ route_head* track = *it; - queue* elem, *tmp; - QUEUE_FOR_EACH(&track->waypoint_list, elem, tmp) { - auto wpt = reinterpret_cast(elem); + foreach (Waypoint* wpt, track->waypoint_list) { track_del_wpt(track, wpt); /* copies any new_trkseg flag forward, and clears new_trkseg flag. */ if (wpt->creation_time.isValid()) { // we will put the merged points in one track segment, @@ -410,7 +406,6 @@ void TrackFilter::trackfilter_split() route_head* master = track_list.first(); int count = master->rte_waypt_ct; - queue* elem, *tmp; int i, j; double interval = -1; /* seconds */ double distance = -1; /* meters */ @@ -490,8 +485,8 @@ void TrackFilter::trackfilter_split() QList buff; - QUEUE_FOR_EACH(&master->waypoint_list, elem, tmp) { - buff.append(reinterpret_cast(elem)); + foreach (Waypoint* wpt, master->waypoint_list) { + buff.append(wpt); } trackfilter_split_init_rte_name(master, buff.at(0)->GetCreationTime()); @@ -566,16 +561,13 @@ void TrackFilter::trackfilter_split() void TrackFilter::trackfilter_move() { - queue* elem, *tmp; - qint64 delta = trackfilter_parse_time_opt(opt_move); if (delta == 0) { return; } for (auto track : qAsConst(track_list)) { - QUEUE_FOR_EACH(&track->waypoint_list, elem, tmp) { - auto wpt = reinterpret_cast(elem); + foreach (Waypoint* wpt, track->waypoint_list) { wpt->creation_time = wpt->creation_time.addSecs(delta); } } @@ -587,8 +579,6 @@ void TrackFilter::trackfilter_move() void TrackFilter::trackfilter_synth() { - queue* elem, *tmp; - double last_course_lat; double last_course_lon; double last_speed_lat = std::nan(""); /* Quiet gcc 7.3.0 -Wmaybe-uninitialized */ @@ -600,8 +590,7 @@ void TrackFilter::trackfilter_synth() for (auto track : qAsConst(track_list)) { bool first = true; - QUEUE_FOR_EACH(&track->waypoint_list, elem, tmp) { - auto wpt = reinterpret_cast(elem); + foreach (Waypoint* wpt, track->waypoint_list) { if (opt_fix) { wpt->fix = fix; if (wpt->sat == 0) { @@ -694,7 +683,6 @@ QDateTime TrackFilter::trackfilter_range_check(const char* timestr) void TrackFilter::trackfilter_range() { QDateTime start, stop; // constructed such that isValid() is false, unlike gpsbabel::DateTime! - queue* elem, *tmp; if (opt_start != nullptr) { start = trackfilter_range_check(opt_start); @@ -710,8 +698,7 @@ void TrackFilter::trackfilter_range() while (it != track_list.end()) { route_head* track = *it; - QUEUE_FOR_EACH(&track->waypoint_list, elem, tmp) { - auto wpt = reinterpret_cast(elem); + foreach (Waypoint* wpt, track->waypoint_list) { bool inside; if (wpt->creation_time.isValid()) { bool after_start = !start.isValid() || (wpt->GetCreationTime() >= start); @@ -751,15 +738,13 @@ void TrackFilter::trackfilter_seg2trk() if (!track_list.isEmpty()) { QList new_track_list; for (auto src : qAsConst(track_list)) { - queue* elem, *tmp; new_track_list.append(src); route_head* dest = nullptr; route_head* insert_point = src; int trk_seg_num = 1; bool first = true; - QUEUE_FOR_EACH(&src->waypoint_list, elem, tmp) { - auto wpt = reinterpret_cast(elem); + foreach (Waypoint* wpt, src->waypoint_list) { if (wpt->wpt_flags.new_trkseg && !first) { dest = route_head_alloc(); @@ -807,10 +792,8 @@ void TrackFilter::trackfilter_trk2seg() while (track_list.size() > 1) { route_head* curr = track_list.takeAt(1); - queue* elem, *tmp; bool first = true; - QUEUE_FOR_EACH(&curr->waypoint_list, elem, tmp) { - auto wpt = reinterpret_cast(elem); + foreach (Waypoint* wpt, curr->waypoint_list) { unsigned orig_new_trkseg = wpt->wpt_flags.new_trkseg; wpt->wpt_flags.new_trkseg = 0; @@ -872,14 +855,11 @@ TrackFilter::faketime_t TrackFilter::trackfilter_faketime_check(const char* time void TrackFilter::trackfilter_faketime() { - queue* elem, *tmp; - assert(opt_faketime != nullptr); faketime_t faketime = trackfilter_faketime_check(opt_faketime); for (auto track : qAsConst(track_list)) { - QUEUE_FOR_EACH(&track->waypoint_list, elem, tmp) { - auto wpt = reinterpret_cast(elem); + foreach (Waypoint* wpt, track->waypoint_list) { if (!wpt->creation_time.isValid() || faketime.force) { wpt->creation_time = faketime.start; @@ -914,7 +894,6 @@ bool TrackFilter::trackfilter_points_are_same(const Waypoint* wpta, const Waypoi void TrackFilter::trackfilter_segment_head(const route_head* rte) { - queue* elem, *tmp; double avg_dist = 0; int index = 0; Waypoint* prev_wpt = nullptr; @@ -922,8 +901,8 @@ void TrackFilter::trackfilter_segment_head(const route_head* rte) // (Empirically determined; It's a few dozen feet.) const double ktoo_close = 0.000005; - QUEUE_FOR_EACH(&rte->waypoint_list, elem, tmp) { - auto wpt = reinterpret_cast(elem); + for (auto it = rte->waypoint_list.cbegin(); it != rte->waypoint_list.cend(); ++it) { + auto wpt = *it; if (index > 0) { double cur_dist = gcdist(RAD(prev_wpt->latitude), RAD(prev_wpt->longitude), @@ -935,8 +914,8 @@ void TrackFilter::trackfilter_segment_head(const route_head* rte) } if (cur_dist < ktoo_close) { - if (wpt != reinterpret_castQUEUE_LAST(&rte->waypoint_list)) { - auto next_wpt = reinterpret_castQUEUE_NEXT(&wpt->Q); + if (wpt != rte->waypoint_list.back()) { + auto next_wpt = *std::next(it); if (trackfilter_points_are_same(prev_wpt, wpt) && trackfilter_points_are_same(wpt, next_wpt)) { track_del_wpt(const_cast(rte), wpt); diff --git a/trackfilter.h b/trackfilter.h index 96dd8cecc..7845ed086 100644 --- a/trackfilter.h +++ b/trackfilter.h @@ -23,7 +23,9 @@ #define TRACKFILTER_H_INCLUDED_ #include // for QDateTime +#include // for QList #include // for qint64 + #include "defs.h" // for ARG_NOMINMAX, route_head (ptr only), ARG... #include "filter.h" // for Filter diff --git a/transform.cc b/transform.cc index 6cadb9358..ccb10dfeb 100644 --- a/transform.cc +++ b/transform.cc @@ -20,10 +20,15 @@ */ +#include // for toupper +#include // for atoi + +#include // for foreach + #include "defs.h" #include "filterdefs.h" #include "transform.h" -#include + #if FILTERS_ENABLED @@ -42,13 +47,7 @@ void TransformFilter::transform_waypoints() track_add_head(rte); break; } -#if NEWQ - foreach (Waypoint* wpt, waypt_list) { -#else - queue* elem, *tmp; - QUEUE_FOR_EACH(&waypt_head, elem, tmp) { - Waypoint* wpt = reinterpret_cast(elem); -#endif + foreach (Waypoint* wpt, *global_waypoint_list) { wpt = new Waypoint(*wpt); switch (current_target) { diff --git a/waypt.cc b/waypt.cc index 6a705c05c..d65ea7af1 100644 --- a/waypt.cc +++ b/waypt.cc @@ -19,13 +19,15 @@ */ +#include // for assert #include // for fabs #include // for printf, fflush, fprintf, stdout #include // for time_t +#include // for stable_sort #include // for QByteArray +#include // for QChar #include // for QDateTime -#include #include // for QList #include // for QString, operator== #include // for QTime @@ -34,20 +36,12 @@ #include "defs.h" #include "garmin_fs.h" // for garmin_ilink_t, garmin_fs_s, GMSD_FIND, garmin_fs_p #include "grtcirc.h" // for RAD, gcdist, heading_true_degrees, radtometers -#include "queue.h" // for queue, QUEUE_INIT, dequeue, QUEUE_FOR_EACH, QUEUE_MOVE, ENQUEUE_TAIL #include "session.h" // for curr_session, session_t #include "src/core/datetime.h" // for DateTime #include "src/core/logging.h" // for Warning, Fatal -#if NEWQ -QList waypt_list; -queue waypt_head; // This is here solely to freak out the formats that are -// looking into what should be a private members. -#else -queue waypt_head; -#endif +WaypointList* global_waypoint_list; -static unsigned int waypt_ct; static short_handle mkshort_handle; geocache_data Waypoint::empty_gc_data; static global_trait traits; @@ -61,11 +55,7 @@ void waypt_init() { mkshort_handle = mkshort_new_handle(); -#if NEWQ - waypt_list.clear(); -#else - QUEUE_INIT(&waypt_head); -#endif + global_waypoint_list = new WaypointList; } void update_common_traits(const Waypoint* wpt) @@ -87,97 +77,22 @@ void update_common_traits(const Waypoint* wpt) void waypt_add(Waypoint* wpt) { - double lat_orig = wpt->latitude; - double lon_orig = wpt->longitude; -#if NEWQ - waypt_list.append(wpt); -#else - ENQUEUE_TAIL(&waypt_head, &wpt->Q); - waypt_ct++; -#endif - - - if (wpt->latitude < -90) { - wpt->latitude += 180; - } else if (wpt->latitude > +90) { - wpt->latitude -= 180; - } - if (wpt->longitude < -180) { - wpt->longitude += 360; - } else if (wpt->longitude > +180) { - wpt->longitude -= 360; - } - - if ((wpt->latitude < -90) || (wpt->latitude > 90.0)) - Fatal() << wpt->session->name - << "Invalid latitude" << lat_orig << "in waypoint" - << wpt->shortname; - if ((wpt->longitude < -180) || (wpt->longitude > 180.0)) - Fatal() << "Invalid longitude" << lon_orig << "in waypoint" - << wpt->shortname; - - /* - * Some input may not have one or more of these types so we - * try to be sure that we have these fields even if just by - * copying them from elsewhere. - */ - - // Note tests for isNull here as some formats intentionally set "". - // This is kind of goofy, but it emulates the C string implementation. - if (wpt->shortname.isNull()) { - if (!wpt->description.isNull()) { - wpt->shortname = wpt->description; - } else if (!wpt->notes.isNull()) { - wpt->shortname = wpt->notes; - } else { - QString n; - n.sprintf("%03d", waypt_count()); - wpt->shortname = QString("WPT%1").arg(n); - } - } - - if (wpt->description.isEmpty()) { - if (!wpt->notes.isNull()) { - wpt->description = wpt->notes; - } else { - if (!wpt->shortname.isNull()) { - wpt->description = wpt->shortname; - } - } - } - - update_common_traits(wpt); - + global_waypoint_list->waypt_add(wpt); } void waypt_del(Waypoint* wpt) { - // the wpt must be on waypt_list, and is assumed unique. -#if NEWQ - waypt_list.removeOne(wpt); -#else - dequeue(&wpt->Q); - waypt_ct--; -#endif + global_waypoint_list->waypt_del(wpt); } unsigned int waypt_count() { -#if NEWQ - return waypt_list.size(); -#else - return waypt_ct; -#endif -} - -void -set_waypt_count(unsigned int nc) -{ - waypt_ct = nc; + return global_waypoint_list->count(); } +// TODO: should this, and mkshort_handle, be part of main, which is the only user? void waypt_disp(const Waypoint* wpt) { @@ -263,128 +178,52 @@ waypt_add_to_bounds(bounds* bounds, const Waypoint* waypointp) void waypt_compute_bounds(bounds* bounds) { - waypt_init_bounds(bounds); -#if NEWQ - foreach (Waypoint* waypointp, waypt_list) { -#else - queue* elem, *tmp; - QUEUE_FOR_EACH(&waypt_head, elem, tmp) { - Waypoint* waypointp = reinterpret_cast(elem); -#endif - waypt_add_to_bounds(bounds, waypointp); - } + global_waypoint_list->waypt_compute_bounds(bounds); } Waypoint* find_waypt_by_name(const QString& name) { -#if NEWQ - foreach (Waypoint* waypointp, waypt_list) { -#else - queue* elem, *tmp; - - QUEUE_FOR_EACH(&waypt_head, elem, tmp) { - Waypoint* waypointp = reinterpret_cast(elem); -#endif - if (waypointp->shortname == name) { - return waypointp; - } - } - - return nullptr; + return global_waypoint_list->find_waypt_by_name(name); } -#if NEWQ void -waypt_flush(queue* head) +waypt_flush_all() { -// TODO: This is incorrect when head != &waypt_head -// We need to pass in a QList instead of a queue* that we ignore! - if (head != &waypt_head) { - if (global_opts.debug_level >= 1) { - warning("NEWQ version of waypt_flush is unimplemented for this list.\n"); - } - } else { - while (!waypt_list.isEmpty()) { - delete waypt_list.takeFirst(); - } + if (mkshort_handle) { + mkshort_del_handle(&mkshort_handle); } + global_waypoint_list->flush(); } -#else + void -waypt_flush(queue* head) +waypt_append(WaypointList* src) { - queue* elem, *tmp; - - QUEUE_FOR_EACH(head, elem, tmp) { - Waypoint* q = reinterpret_cast(dequeue(elem)); - delete q; - if (head == &waypt_head) { - waypt_ct--; - } - } + src->copy(&global_waypoint_list); } -#endif void -waypt_flush_all() +waypt_backup(WaypointList** head_bak) { - if (mkshort_handle) { - mkshort_del_handle(&mkshort_handle); - } -#if NEWQ - // TODO: eventually we shoud pass the list instead of the queue. - waypt_flush(&waypt_head); -#else - waypt_flush(&waypt_head); -#endif + global_waypoint_list->copy(head_bak); } void -waypt_backup(signed int* count, queue** head_bak) +waypt_restore(WaypointList* head_bak) { - queue* elem, *tmp; - Waypoint* wpt; - int no = 0; - - queue* qbackup = (queue*) xcalloc(1, sizeof(*qbackup)); - QUEUE_INIT(qbackup); -#if NEWQ -// Why does this code exist? -//abort(); -#else - QUEUE_MOVE(qbackup, &waypt_head); - QUEUE_INIT(&waypt_head); -#endif - - waypt_ct = 0; - - QUEUE_FOR_EACH(qbackup, elem, tmp) { - wpt = reinterpret_cast(elem); - waypt_add(new Waypoint(*wpt)); - no++; - } - - *head_bak = qbackup; - *count = no; + global_waypoint_list->restore(head_bak); } void -waypt_restore(signed int count, queue* head_bak) +waypt_swap(WaypointList& other) { - if (head_bak == nullptr) { - return; - } + global_waypoint_list->swap(other); +} -#if NEWQ -//abort(); -#else - waypt_flush(&waypt_head); - QUEUE_INIT(&waypt_head); - QUEUE_MOVE(&waypt_head, head_bak); -#endif - waypt_ct = count; - xfree(head_bak); +void +waypt_sort(WaypointList::Compare cmp) +{ + global_waypoint_list->sort(cmp); } void @@ -568,7 +407,6 @@ waypt_course(const Waypoint* A, const Waypoint* B) } Waypoint::Waypoint() : - // Q(), latitude(0), // These should probably use some invalid data, but longitude(0), // it looks like we have code that relies on them being zero. altitude(unknown_alt), @@ -593,7 +431,6 @@ Waypoint::Waypoint() : session(curr_session()), extra_data(nullptr) { - QUEUE_INIT(&Q); } Waypoint::~Waypoint() @@ -605,7 +442,6 @@ Waypoint::~Waypoint() } Waypoint::Waypoint(const Waypoint& other) : - // Q(other.Q), latitude(other.latitude), longitude(other.longitude), altitude(other.altitude), @@ -642,12 +478,6 @@ Waypoint::Waypoint(const Waypoint& other) : gc_data = new geocache_data(*other.gc_data); } - /* - * It's important that this duplicated waypoint not appear - * on the master Q. - */ - QUEUE_INIT(&Q); - // deep copy fs chain data. fs = fs_chain_copy(other.fs); @@ -666,7 +496,6 @@ Waypoint& Waypoint::operator=(const Waypoint& rhs) fs_chain_destroy(fs); // allocate and copy - // Q(rhs.Q), latitude = rhs.latitude; longitude = rhs.longitude; altitude = rhs.altitude; @@ -702,12 +531,6 @@ Waypoint& Waypoint::operator=(const Waypoint& rhs) gc_data = new geocache_data(*rhs.gc_data); } - /* - * It's important that this duplicated waypoint not appear - * on the master Q. - */ - QUEUE_INIT(&Q); - // deep copy fs chain data. fs = fs_chain_copy(rhs.fs); @@ -750,7 +573,6 @@ Waypoint::CreationTimeXML() const } QDateTime dt = GetCreationTime().toUTC(); -// qDebug() << dt.toString("dd.MM.yyyy hh:mm:ss.zzz") << " CML " << microseconds; const char* format = "yyyy-MM-ddTHH:mm:ssZ"; if (dt.time().msec()) { @@ -799,3 +621,167 @@ Waypoint::EmptyGCData() const { return (gc_data == &Waypoint::empty_gc_data); } + +void +WaypointList::waypt_add(Waypoint* wpt) +{ + double lat_orig = wpt->latitude; + double lon_orig = wpt->longitude; + append(wpt); + + if (wpt->latitude < -90) { + wpt->latitude += 180; + } else if (wpt->latitude > +90) { + wpt->latitude -= 180; + } + if (wpt->longitude < -180) { + wpt->longitude += 360; + } else if (wpt->longitude > +180) { + wpt->longitude -= 360; + } + + if ((wpt->latitude < -90) || (wpt->latitude > 90.0)) + Fatal() << wpt->session->name + << "Invalid latitude" << lat_orig << "in waypoint" + << wpt->shortname; + if ((wpt->longitude < -180) || (wpt->longitude > 180.0)) + Fatal() << "Invalid longitude" << lon_orig << "in waypoint" + << wpt->shortname; + + /* + * Some input may not have one or more of these types so we + * try to be sure that we have these fields even if just by + * copying them from elsewhere. + */ + + // Note tests for isNull here as some formats intentionally set "". + // This is kind of goofy, but it emulates the C string implementation. + if (wpt->shortname.isNull()) { + if (!wpt->description.isNull()) { + wpt->shortname = wpt->description; + } else if (!wpt->notes.isNull()) { + wpt->shortname = wpt->notes; + } else { + QString n; + n.sprintf("%03d", waypt_count()); + wpt->shortname = QString("WPT%1").arg(n); + } + } + + if (wpt->description.isEmpty()) { + if (!wpt->notes.isNull()) { + wpt->description = wpt->notes; + } else { + if (!wpt->shortname.isNull()) { + wpt->description = wpt->shortname; + } + } + } + + if (this == global_waypoint_list) { + update_common_traits(wpt); + } + +} + +void +WaypointList::add_rte_waypt(int waypt_ct, Waypoint* wpt, bool synth, const QString& namepart, int number_digits) +{ + append(wpt); + + if (synth && wpt->shortname.isEmpty()) { + wpt->shortname = QString("%1%2").arg(namepart).arg(waypt_ct, number_digits, 10, QChar('0')); + wpt->wpt_flags.shortname_is_synthetic = 1; + } +} + +void +WaypointList::waypt_del(Waypoint* wpt) +{ + const int idx = this->indexOf(wpt); + assert(idx >= 0); + removeAt(idx); +} + +void +WaypointList::del_rte_waypt(Waypoint* wpt) +{ + const int idx = indexOf(wpt); + assert(idx >= 0); + if (wpt->wpt_flags.new_trkseg && ((idx+1) < size())) { + auto wpt_next = at(idx+1); + wpt_next->wpt_flags.new_trkseg = 1; + } + wpt->wpt_flags.new_trkseg = 0; + removeAt(idx); +} + +/* + * Makes another pass over the data to compute bounding + * box data and populates bounding box information. + */ + +void +WaypointList::waypt_compute_bounds(bounds* bounds) const +{ + waypt_init_bounds(bounds); + foreach (const Waypoint* waypointp, *this) { + waypt_add_to_bounds(bounds, waypointp); + } +} + +Waypoint* +WaypointList::find_waypt_by_name(const QString& name) const +{ + foreach (Waypoint* waypointp, *this) { + if (waypointp->shortname == name) { + return waypointp; + } + } + + return nullptr; +} + +void +WaypointList::flush() +{ + while (!isEmpty()) { + delete takeFirst(); + } +} + +void +WaypointList::copy(WaypointList** dst) const +{ + if (*dst == nullptr) { + *dst = new WaypointList; + } + + foreach (const Waypoint* wpt_old, *this) { + (*dst)->waypt_add(new Waypoint(*wpt_old)); + } +} + +void +WaypointList::restore(WaypointList* src) +{ + if (src == nullptr) { + return; + } + flush(); + + *this = *src; + src->clear(); +} + +void WaypointList::swap(WaypointList& other) +{ + const WaypointList tmp_list = *this; + *this = other; + other = tmp_list; +} + +void WaypointList::sort(Compare cmp) +{ + std::stable_sort(begin(), end(), cmp); +}